5.01

Cart Components

Describe cart components from user and developer perspectives: Quote, items, addresses, totals, renderers, and quote merge behavior.

Why This Matters: Understanding cart components from both user and developer perspectives is essential to implement add-to-cart flows, totals recalculation, item rendering, and address handling reliably, especially across edge cases like quote merging.

Cart Components Overview

mindmap root((Cart Components)) User View Shopping cart Cart items (minicart/cart page) Shipping address (estimates) Discounts (coupon) Totals (subtotal, discount, tax) Dev View Quote (Magento\Quote\Model\Quote) Cart (Magento\Checkout\Model\Cart) Items (Quote\Item) Address (Quote\Address) Totals (Total models) Renderers (by product type) Merge Quotes

Cart Components (End‑User Perspective)

  • Shopping cart: Triggered when a product is added. Products can appear via multiple flows:
    1. Add to Cart on product/category pages.
    2. Reorder from My Account (products may have changed).
    3. Wishlist moving items to cart.
    4. Quote merge after login (guest cart merged with customer cart).
  • Cart items: Viewed on the cart page and in the minicart.
  • Shipping address: Estimate section on cart page triggers shipping price calculation (typical of checkout).
  • Discounts: Apply coupon codes (managed by Promo Rules).
  • Totals: Subtotal, discount, tax (also in minicart).

Cart Components (Developer Perspective)

Quote vs Cart

  • Cart wrapper: Magento\Checkout\Model\Cart wraps Magento\Quote\Model\Quote.
  • Quote: The core model that owns items and addresses, decides totals recollection, holds payment (checkout scope), and merges/collects data.
Magento/Quote/Model/Quote.php
Key responsibilities: add product/items, collect totals, manage addresses, merge quotes, determine virtual status.
Important Quote methods:
  • beforeSave(), *load(), assignCustomer()
  • getBillingAddress(), getShippingAddress(), getAllShippingAddresses() (multi-shipping)
  • getAllItems(), getAllVisibleItems()
  • addItem(), addProduct(), updateItem()
  • getIsVirtual(), merge(), collectTotals()

Cart Items

Items are represented by Magento\Quote\Model\Quote\Item. Though items are fetched through Quote, they are actually attached to Quote Address (shipping vs billing for virtual items).

  • representProduct() decides whether two added products should join (increase qty) or be separate line items.
  • setProduct() prepares product attributes on the item.

Rendering: Item renderers are configured via layout per product type, e.g. Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml.

Product types: simple → one item; configurable → parent (configurable SKU) + child (selected SKU); bundle → bundle SKU + one per selection; grouped → selected SKUs as separate items.

Addresses

Both shipping and billing use Magento\Quote\Model\Quote\Address. Physical items attach to shipping address; virtual items to billing. Multi-shipping supports multiple shipping addresses.

  • getAllItems(), getAllVisibleItems()
  • getShippingRatesCollection(), requestShippingRates() (see shipping methods/rates)

Totals Framework

Totals (Subtotal, Tax, Discount, Shipping, Grand Total, etc.) are computed via Total models registered in etc/sales.xml (e.g., Magento/Quote/etc/sales.xml).

  • Total model collect() calculates its amount into Magento\Quote\Model\Address\Total (the totals container).
  • Total model fetch() returns data used for UI rendering.
\Magento\Quote\Model\Quote\Address\Total\Subtotal

Quote Merge

When a guest adds items then logs in, Magento merges the guest quote with the customer's active quote. This is a frequent source of edge cases—plan for option conflicts, availability changes, and totals recollection.

Further Reading

Exam Tips

  • Quote vs Cart: Cart wraps Quote; Quote owns items, addresses, totals recollection, merge.
  • Items: representProduct() decides line joining; renderers vary by product type.
  • Address: Shipping vs billing (virtual). Can have multiple shipping addresses (multishipping).
  • Totals: Registered in etc/sales.xml; total models implement collect()/fetch().
  • Flows: Add to cart, reorder, wishlist, quote merge—test them all.