cart-logic

Manage shopping cart state and persistence across devices for Shopify, WooCommerce, BigCommerce, and headless storefronts.

14|3|Updated Mar 22, 2026
One-click install
npx skills add https://github.com/tomtoto757/ecomm-ai-skills-hub --skill cart-logic-tomtoto757
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cart-logic
Source: https://github.com/tomtoto757/ecomm-ai-skills-hub/tree/main/skills/checkout-payments-tax/finsilabs/payments-checkout/cart-logic
Command: npx skills add https://github.com/tomtoto757/ecomm-ai-skills-hub --skill cart-logic-tomtoto757

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cart logic ensures shoppers' intended purchases are tracked reliably across page loads, devices, and authentication events so items are not lost, duplicated, or mispriced at checkout. It addresses missing persistence, guest carts disappearing after login, inconsistent totals caused by client-side calculations, and the need for platform-specific versus headless implementations.

Core Features & Use Cases

  • Add / Remove / Update: Correct upsert semantics for line items so adding the same variant increments quantity instead of creating duplicates.
  • Persistence & Session Management: Persist guest carts across sessions (recommended as an httpOnly guest token cookie) and support server-side cart storage for logged-in users.
  • Guest → User Merge: Merge guest carts into a user's account on login while preserving audit history for guest carts and resolving conflicts sensibly.
  • Server-side Totals & Validation: Capture unit price at add time, validate stock on add, and always recalculate subtotal, discounts, and totals server-side.
  • Platform Coverage: Practical guidance for Shopify, WooCommerce, BigCommerce, and headless Storefront API implementations.

Quick Start

Create a persistent cart, add variant variantGid with quantity 1, and merge the guest cart into the user's account on login.

Frequently Asked Questions about cart-logic

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I merge a guest cart into a user account on login without duplicating items?

To merge a guest cart into a user account on login, apply upsert semantics to line items and resolve max-quantity conflicts. This ensures adding the same variant increments quantity instead of creating duplicates, while preserving audit history for guest carts.

Why do my client-side cart totals differ from checkout, and how can I fix it?

Client-side cart totals often differ due to stale pricing data. You should capture the unit price at add time and always recalculate subtotals, discounts, and totals server-side to ensure checkout consistency and prevent mispriced items.

Does this cart logic work with headless storefronts and platforms like Shopify?

Yes, this cart logic works with headless storefronts, Shopify, WooCommerce, and BigCommerce. It provides practical guidance for managing cart state, persistent guest sessions, and server-side subtotal recalculation across these specific ecommerce platforms.

What is the best way to persist a guest shopping cart across sessions and page loads?

The best way to persist a guest shopping cart across sessions is using an httpOnly guest token cookie paired with server-side cart storage. This ensures shoppers' intended purchases are reliably tracked across page loads and devices without disappearing.

How do I validate stock and handle add-to-cart operations correctly?

To validate stock and handle add-to-cart operations correctly, you must validate stock availability on add and apply correct upsert semantics. This tracks items reliably so intended purchases are not lost, duplicated, or mispriced at checkout.

When should I use server-side cart state management instead of client-side?

You should use server-side cart state management when you need to prevent inconsistent totals, ensure reliable persistence across devices, and handle guest-to-user merge scenarios. This approach avoids missing persistence and guest carts disappearing after login.