NAV

Get Cart Details

Find out more about cart in its current state.

Cart Object

Cart object is a snapshot of essential shopping cart properties, passed via various callbacks. Cart object does not provide direct memory access to the actual cart that Ecwid uses — i.e. changing this exact object will not alter the actual cart Ecwid uses for placing the order.

Get quantity of products in cart example

Ecwid.OnCartChanged.add(function(cart) {
  console.log("Products in cart now: " + cart.productsQuantity);
})

// prints
// Products in cart now: 1

Fields:

NameTypeDescription
itemsArray<CartItem>Enlists all items currently present in customer’s cart
productsQuantityintegerTotal number of product varieties in cart
orderIdintegerUnique internal order ID for this order (available after order is created)
couponNamestringThe name of the coupon (if any) applied to the cart. If no coupon was applied, will contain undefined. Does not contain the actual code of coupon, just the name.
weightnumberTotal weight of the items in cart
paymentMethodstringThe name of the selected payment method (if any)
shippingMethodstringThe name of the selected shipping method (if any)

Order Object

Order object represents details of current customer’s order.

Get order total example

Ecwid.Cart.calculateTotal(function(order) {
  console.log(order.total);
})

// prints
// 13.25

Fields:

NameTypeDescription
cart<Cart>The object describing the state or customer’s cart
couponDiscountintegerAn absolute amount of coupon code discount for this order
customerGroupDiscountintegerAn absolute amount of a discount based on customer group for this order
customerGroupVolumeDiscountintegerAn absolute amount of a discount based on customer group and subtotal for this order
discountintegerAn absolute amount of a total discount for this order
handlingFeeintegerAn absolute amount of handling fee applied to order
shippingintegerAn absolute amount of shipping rate applied to order
taxintegerAn absolute amount of tax rate applied to order
totalintegerTotal amount of this order
volumeDiscountintegerAn absolute amount of a discount based on subtotal for this order

CartItem Object

CartItem represents a single item (product variety) in cart.

Get quantity of a product in cart example

Ecwid.OnCartChanged.add(function(cart) {
  console.log("There are " + cart.items[0].quantity + " items of " + cart.items[0].product.name + " in cart now.");
})

// prints
// There are 1 items of Apple product in cart now.

Fields:

NameTypeDescription
quantityintegerQuantity of the given product variety in cart
productArray<Product>The map of product properties (variation properties, if the variation is added to cart)
optionsObject with option names and valuesMap of the product options (option name as a key and option value as a value). For listboxes and radio buttons value will be the string value of the selected option. For checkboxes — names of the selected options, comma separated. For date options — string representing the selected date according to the shop’s format (Ecwid control panel > System settings > General > Formats and Units). For textboxes и textareas — the text given by the customer. For file upload options — string in the form of „4 files”

Product Object

Product object represents details of a specific product in cart

Get product name and SKU in cart example

Ecwid.OnCartChanged.add(function(cart) {
  console.log(cart.items[0].product.name + " in the cart has SKU: " + cart.items[0].product.sku);
})

// prints
// Apple product in the cart has SKU: TEST-1234

Fields:

NameTypeDescription
idintegerInternal unique product ID
nameitringProduct name
priceintegerProduct price
shortDescriptionstringProduct description truncated to 120 characters
skustringProduct SKU
urlstringURL to this product details page in store front (store front URL is generated from a field in Ecwid Control panel > Settings > General > Store profile)
weightintegerWeight of a product