Cart Management
Cart
The Cart class represents a shopping cart with items and related data.getItems(): Get all cart itemsgetItem(uuid): Get specific item by UUIDcreateItem(productId, qty): Create a new cart itemgetData(key): Get cart data by keysetData(key, value): Set cart dataexport(): Export full cart dataexportData(): Export cart data for database
Item
The Item class represents a single cart item.getData(key): Get item data by keysetData(key, value): Set item dataexport(): Export item datahasError(): Check if item has errorsgetErrors(): Get item validation errors
getMyCart
Retrieves the current active cart by session ID and optional customer ID.sid(string): Session IDcustomerId(number, optional): Customer ID for retrieving abandoned carts
- First attempts to find cart by session ID
- If not found and customer ID provided, looks for abandoned cart
- Updates abandoned cart with current session ID if found
createNewCart
Creates a new empty cart.data(object): Initial cart datasid(string): Session IDcustomer_id(number, optional): Customer IDcurrency(string): Currency code
getCartByUUID
Retrieves a cart by its UUID.uuid(string): Cart UUID
addCartItem
Adds a product to the cart.cart(Cart): Cart instanceproductID(number): Product ID to addqty(number|string): Quantity to addcontext(object): Context object for hooks
- Validates product availability and quantity
- Checks for duplicate items and merges quantities
- Runs validation hooks before adding
- Throws error if validation fails
updateCartItemQty
Updates the quantity of a cart item.cart(Cart): Cart instanceitemUuid(string): Item UUIDqty(number): New quantity
removeCartItem
Removes an item from the cart.cart(Cart): Cart instanceitemUuid(string): Item UUID to remove
saveCart
Persists cart data to the database.cart(Cart): Cart instance to save
- Deletes cart if no items remain
- Creates new cart record or updates existing
- Synchronizes cart items with database
- Removes deleted items from database
Address Management
addShippingAddress
Adds or updates shipping address for the cart.cart(Cart): Cart instanceaddress(object): Shipping address datafull_name(string): Recipient nameaddress_1(string): Address line 1address_2(string, optional): Address line 2city(string): Cityprovince(string): State/Provincepostcode(string): Postal codecountry(string): Country codetelephone(string): Phone number
addBillingAddress
Adds or updates billing address for the cart.cart(Cart): Cart instanceaddress(object): Billing address data (same structure as shipping)
Payment & Shipping
getAvailablePaymentMethods
Retrieves available payment methods for the cart.cart(Cart): Cart instance
getAvailableShippingMethods
Retrieves available shipping methods for the cart.cart(Cart): Cart instance
Order Creation
createOrder
Creates an order from a cart.cart(Cart): Cart instance to create order from
order_id(number): Order IDuuid(string): Order UUIDorder_number(number): Human-readable order numbergrand_total(number): Order totalstatus(string): Order statuspayment_status(string): Payment statusshipment_status(string): Shipment status
- Validates cart data (addresses, items, payment method)
- Creates order record with addresses
- Copies cart items to order items
- Adds order activity log
- Disables the cart
- Commits transaction or rolls back on error
orderValidator
Validates cart before order creation.cart(Cart): Cart instance to validate
valid(boolean): Validation statuserrors(array): Array of error messages
- Cart has items
- Billing address is present
- Shipping address is present (if required)
- Payment method is selected
- All items are in stock
Utility Services
toPrice
Formats a number as a price string.amount(number): Amount to formatcurrency(string): Currency code