Cart Components
Describe cart components from user and developer perspectives: Quote, items, addresses, totals, renderers, and quote merge behavior.
Cart Components Overview
Cart Components (End‑User Perspective)
- Shopping cart: Triggered when a product is added. Products can appear via multiple flows:
- Add to Cart on product/category pages.
- Reorder from My Account (products may have changed).
- Wishlist moving items to cart.
- 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\CartwrapsMagento\Quote\Model\Quote. - Quote: The core model that owns items and addresses, decides totals recollection, holds payment (checkout scope), and merges/collects data.
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.
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 implementcollect()/fetch(). - Flows: Add to cart, reorder, wishlist, quote merge—test them all.