How Magento's Shopping Cart Works — and Why It's Complex
Magento's cart is built around the Quote model — a database entity that stores the entire state of a shopping session: items, quantities, pricing (including tier prices, catalog rules and cart rules), applied coupons, shipping information, and customer-specific data. Every cart interaction triggers a collectTotals() process that re-evaluates the entire quote from scratch.
This architecture is powerful and flexible — but it means that custom cart logic must integrate carefully with the totals collection pipeline, and that performance depends heavily on how efficiently that pipeline is implemented. A poorly written custom price total or an extension that loads unnecessary data on every cart page view can make the cart unusably slow.
Understanding the quote lifecycle is the foundation of good Magento cart development. Dahlquist's developers have worked with this system across more than 150 projects — from simple custom fields to fully custom B2B cart flows with procurement system integration.
The Magento quote/cart data flow
- Quote items — each product in the cart, with its own price, qty and custom options
- Quote addresses — shipping and billing addresses, each with their own totals
- Total collectors — ordered list of classes that calculate subtotal, tax, shipping, discounts, etc.
- Quote extensions — custom attributes added to the quote via extension attributes
- Cart sections — serialised cart data cached in the browser, invalidated via AJAX section loading
Custom Cart and Checkout Capabilities
Custom checkout steps and fields
Add fields to the Magento checkout — delivery date picker, project code, purchase order number, reference field, custom terms acceptance — without breaking native checkout functionality. We use Magento's UI component system and save values through the quote to the order.
B2B cart logic
Customer-specific price rules applied at cart level, minimum order quantity enforcement, customer group discounts, order approval workflows that hold the order pending manager sign-off, and purchase order number capture integrated into the quote model.
Custom total collectors
Implement custom line items in the cart: handling fees, environmental fees, pallet charges, custom discount structures or surcharges based on cart contents, customer type or shipping zone. Built as proper Magento total collectors that integrate with the tax system.
Multi-address checkout
Allow B2B customers to split a single order across multiple delivery addresses — critical for companies ordering on behalf of multiple departments or locations. Fully integrated with Magento's multi-shipping checkout flow and ERP order splitting.
Payment method integration
Native integration with Klarna Checkout, Stripe, Adyen, Svea Ekonomi, Nets Easy and invoice payment for B2B — with fallback logic, retry handling and proper error state management. We implement payment methods as proper Magento payment modules, not iframes with workarounds.
PunchOut checkout
cXML and OCI PunchOut checkout for B2B merchants selling to procurement-driven buyers using SAP Ariba, Coupa, Jaggaer or Basware. Full session management, contract pricing integration and return cart message handling.
Cart Performance Optimisation
A slow cart page is a conversion killer. Every additional second of cart load time reduces the probability of checkout by 7–10%. Magento carts become slow for predictable reasons — and all of them are fixable once you know where to look.
Common cart performance problems and fixes
- Unoptimised quote collection queries — loading all quote items with full product objects instead of using join queries. Fix: use
addAttributeToSelect()selectively and join only needed data. - Price rules evaluated against full product collection — cart rules that load and iterate all products in the catalog to check applicability. Fix: redesign rule conditions to use indexed data.
- Synchronous shipping rate requests on cart load — calling external shipping APIs on every page view. Fix: debounce shipping estimation requests and cache results per shipping zone.
- Full-page cache misconfiguration — cart pages are not cacheable by design, but the surrounding layout often is. Fix: configure FPC hole punching correctly so the page frame is cached while the cart section loads via AJAX.
- Mini-cart invalidation on every request — extensions that invalidate the
cartsection unnecessarily on every request. Fix: audit section invalidation config in all installed extensions. - No Redis for session storage — using file-based sessions causes locking and slowness under concurrent load. Fix: configure Redis as session storage with proper locking timeout settings.
Tools we use for cart performance diagnosis
Magento Developer Toolbar Blackfire.io New Relic APM MySQL slow query log Chrome DevTools Network Lighthouse
PunchOut Checkout: Selling Into Procurement Systems
Enterprise and public sector buyers often require that all purchases pass through their procurement system before a purchase order is issued. PunchOut checkout is the integration that enables this — and without it, you simply cannot sell to these buyers at all.
How Magento PunchOut works (cXML protocol)
PunchOut Setup Request
The buyer's procurement system (SAP Ariba, Coupa, Jaggaer) sends a cXML PunchOut Setup Request to your Magento store. Magento authenticates the buyer, loads their contract pricing and creates a session.
Buyer shops in your store
The buyer is redirected to your Magento store and shops normally. They see their negotiated prices, their approved product catalog and their language. The cart behaves as a standard Magento cart.
Transfer Cart (instead of standard checkout)
Instead of a standard checkout, the buyer clicks "Transfer Cart" (or "Return Cart"). Magento generates a cXML PunchOut Order Message containing all cart items, quantities and prices, and posts it back to the procurement system.
Procurement approval
The procurement system creates a purchase requisition from the cart data. The requisition goes through the buyer's internal approval workflow (department manager, procurement controller, etc.).
Purchase Order received by Magento
Once approved, the procurement system sends a cXML Purchase Order (or EDI 850) to Magento. Magento creates the order automatically, triggers ERP order ingestion and sends confirmation to the buyer.
Dahlquist implements both cXML and OCI PunchOut protocols. We test against the buyer's actual procurement system before go-live — not just against a test harness.
Technology Stack
Magento 2.4.x Adobe Commerce Cloud PHP 8.1 / 8.2 GraphQL API Hyva Theme Alpine.js Elasticsearch / OpenSearch Redis Varnish / Fastly Docker / Warden Blackfire.io New Relic
Frequently Asked Questions about Magento Cart Development
How does Magento's shopping cart work technically?
Magento's cart is built around the Quote model — a database record storing all cart state. Every cart action triggers a collectTotals() process that recalculates the entire cart via an ordered pipeline of total collector classes. Custom cart development means extending this system through plugins, observers and custom total collectors, while maintaining compatibility with Magento's native tax, shipping and discount systems.
How do I add a custom field to Magento checkout?
Adding a custom field requires: a custom module, a UI component in the checkout layout, a JavaScript mixin for the checkout model, a plugin on ShippingInformationManagement to save the field to the quote, and an observer to copy it to the order on placement. Dahlquist has a battle-tested pattern for this that handles all edge cases including guest checkout and multi-shipping.
Why is my Magento cart page slow?
Almost always caused by: unoptimised quote collection queries, price rules evaluated against the full product collection, synchronous shipping rate requests on every load, FPC misconfiguration, or mini-cart section being invalidated on every request. Profile with the Magento developer toolbar or Blackfire.io to find the actual bottleneck before optimising.
What is the difference between Magento's mini-cart and the cart page?
The mini-cart is a sidebar component loaded via Magento's section cache (stored in localStorage, refreshed asynchronously via AJAX when sections are invalidated). The cart page is a full page rendering the complete quote. Custom development often involves both — the cart page for full interactions and the mini-cart section for the lightweight sidebar view.
How does PunchOut checkout work in Magento?
The buyer's procurement system sends a cXML PunchOut Setup Request to Magento, which creates an authenticated session with contract pricing. The buyer shops and adds items, then clicks "Transfer Cart" — which sends a cXML PunchOut Order Message back to the procurement system instead of checking out. The procurement system processes the requisition, and when approved, sends a Purchase Order to Magento that triggers automatic order creation.
Can Magento handle B2B order approval workflows in the cart?
Yes — Adobe Commerce B2B includes native purchase approval workflows. Orders above a configured threshold are held pending manager approval before processing. The cart converts to a pending order visible in the company account dashboard. Magento Open Source can achieve similar functionality through custom development or third-party extensions.