Skip to content

Cart Controllers ​

Two controllers manage cart functionality: cart for the full cart page and cart-drawer for the slide-out mini cart.

Cart Controller ​

Source: src/js/controllers/cart-controller.js (~600 lines)

Manages the full cart page with item editing, quantity updates, and coupon/gift card application.

Targets ​

TargetElementPurpose
itemListCart items containerRenders cart line items
subtotalSubtotal displayCart subtotal
grandTotalGrand total displayTotal after tax/discounts
couponInputCoupon code inputApply coupon codes
couponMessageFeedback areaSuccess/error messages
emptyMessageEmpty cart noticeShown when cart is empty
checkoutButtonProceed to checkoutDisabled when cart empty

Key Actions ​

ActionBehavior
updateQtyPATCH item quantity, re-render totals
removeItemDELETE item from cart
applyCouponPOST coupon code
removeCouponDELETE applied coupon

Cart API Flow ​

Cart Drawer Controller ​

Source: src/js/controllers/cart-drawer-controller.js (~600 lines)

Manages the slide-out cart drawer that appears when items are added.

Targets ​

TargetElementPurpose
drawerDrawer containerSlide-in panel
backdropOverlayClick to close
itemsItem listMini cart items
totalTotal displayCart total
badgeCart count badgeItem count in header

Key Actions ​

ActionBehavior
openSlide drawer in from right
closeSlide drawer out, remove backdrop
removeItemRemove item and re-render

Events ​

The cart drawer listens for custom events:

javascript
// Dispatched by product controller after add-to-cart
document.dispatchEvent(new CustomEvent('cart:updated', { detail: { cart } }));

// Cart drawer catches it and opens with updated contents

Drawer Animation ​

The drawer uses CSS transitions:

css
.cart-drawer {
  transform: translateX(100%);
  transition: transform var(--transition-base) ease;
}
.cart-drawer.open {
  transform: translateX(0);
}

Source: src/js/controllers/cart-controller.js, src/js/controllers/cart-drawer-controller.js