VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/6.4-shopping-cart-and-checkout

⇱ Shopping Cart and Checkout | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Shopping Cart and Checkout

Purpose and Scope

This document provides a detailed technical overview of Maho's shopping cart and checkout system. It covers the core Quote system that underpins the shopping cart, the process for adding products to the cart, the checkout flow including the one-step checkout UI, shipping and totals calculation, PayPal Express integration, and payment processing mechanics.

This page targets developers who need to understand the implementation details, data flow, and integration points for the shopping cart and checkout functionality.


Quote System Architecture

The shopping cart in Maho is implemented as a Quote, a mutable entity representing the customer's current shopping session. It holds all quote items, addresses, payment info, and totals, and upon order placement converts into an immutable Order entity.

Core Quote Entities and Relationships


  • Mage_Checkout_Model_Session maintains the ongoing quote in session storage.
  • Mage_Checkout_Model_Cart offers business logic to add/remove items and interact with the active quote.
  • Mage_Sales_Model_Quote is the main data model for the cart contents and quote data.
  • Quote addresses and payments are managed by Mage_Sales_Model_Quote_Address and Mage_Sales_Model_Quote_Payment.
  • Each QuoteItem associates a product with quantity and custom options.

Sources: app/code/core/Mage/Checkout/controllers/CartController.php20-43 app/code/core/Mage/Checkout/Helper/Data.php26-39

Quote Lifecycle: Add Product Flow


When a user adds a product to the cart, the controller initializes the product model, validates the request, and delegates to the cart model to add the product to the quote. Totals are re-calculated and the quote saved. The controller then returns a response, which in modern UX may be a JSON payload for dynamic UI updates.

Sources: app/code/core/Mage/Checkout/controllers/CartController.php173-240


Quote Management

Mage_Sales_Model_Quote Model

The primary model for cart management encapsulates:

  • Customer and store context.
  • Collections of QuoteItem objects.
  • Shipping and billing addresses.
  • Payment details.
  • Coupon codes and price totals.

This model handles total collection and validation, including minimum order amount checks on display. For example, the cart controller adds notices if the minimum order amount is not met.

Checkout Session

Mage_Checkout_Model_Session manages the lifecycle of the quote in user sessions, providing getQuote() to retrieve the active quote for the session.


Adding Products to the Cart

Product Initialization and Validation

The cart controller uses _initProduct() to load the product model for the product ID passed in the request. It validates the product exists and is salable in the current store context before allowing it to be added to the cart.

Frontend AJAX Integration for Add to Cart

In the frontend product view template, the productAddToCartForm.submit function asynchronously submits the add-to-cart request using mahoFetch. Upon success, it dynamically updates the mini-cart UI with the new cart contents and quantity:


This enables a smooth user experience without page reloads when adding items to the cart.

Sources: app/design/frontend/base/default/template/catalog/product/view.phtml99-166 app/code/core/Mage/Checkout/controllers/CartController.php173-240


One-Step Checkout

Maho’s checkout flow features an improved One-Step Checkout (OSC) UI that consolidates multiple steps (billing, shipping, shipping method, payment, review) into a single page with dynamic AJAX updates.

OneStepCheckout JavaScript Controller

OneStepCheckout class manages form submissions and UI updates:

  • Auto-saves billing and shipping information on change with input debouncing.
  • Refreshes shipping methods and payment methods when the customer inputs or updates addresses.
  • Queues AJAX requests sequentially to prevent race conditions.
  • Provides compatibility with legacy accordion UI through a lightweight mock.

This allows the checkout page to dynamically update as the user enters their data, providing immediate feedback on shipping options, tax, totals, and payment methods without page reloads.

Billing Form Template Structure

The billing form (co-billing-form) contains typical EAV fields: names, company, street lines, city, region/state, postcode, and VAT number (if enabled). It supports customer address selection or new address entry. app/design/frontend/base/default/template/checkout/onepage/billing.phtml13-95

Sources: public/js/varien/onestepcheckout.js27-202 app/design/frontend/base/default/template/checkout/onepage/billing.phtml13-95


Shipping and Totals

Shipping Estimation in Cart

On the cart page, customers can estimate shipping costs by entering shipping address data. This data is saved in the checkout session and applied to the quote’s shipping address for rate calculations and cart totals.

Total Calculations and Validation

During quote updates, the collectTotals() method aggregates subtotals, shipping, taxes, discounts, and grand totals. The cart controller checks for minimum order amount configuration and adds a user notice if not met, displaying the configured minimum amount.

Tax utilities in Mage_Checkout_Helper_Data assist in formatting prices with and without tax for display purposes.


Frontend Interactivity: Mini-Cart and UI Elements

Mini-cart Overview

The mini-cart widget in the header shows a condensed view of cart contents and updates dynamically via AJAX when the cart changes. It also uses an offcanvas drawer to slide out the cart details for quick access.

Responsive Design and Styling

  • Responsive breakpoints and CSS variables define layout and color scheme dynamics.
  • The shopping cart and checkout UI adapt gracefully across screen sizes, stacking form input fields or laying out multi-column views as appropriate.
  • The product view templates support updating cart quantity and display refresh dynamically with mahoFetch AJAX calls.

Payment Processing Integration

PayPal Express Checkout

PayPal Express is integrated as an alternative checkout flow.


Summary Diagram: Shopping Cart and Checkout Components to Code Mapping


This diagram illustrates associations between user interface components, relevant controllers, and core models involved in shopping cart and checkout.


References


This concludes the technical overview of Maho's Shopping Cart and Checkout system.