Calculates the cart asynchronously and passes the result as an argument of type Order to the callback.
Cart calculation involves a request to the server, so this method should be called only occasionally. Calling it frequently, e.g. from loops or by timer, is not acceptable.
Since the calculation needs a server connection, it might fail due to network conditions. In this case, null is passed into the callback instead of Order object.
Order object is a snapshot of a currently generating customer's order that contains essential order properties.
The function below allows to get the current order preview and pass the result as an order object.
Ecwid.Cart.calculateTotal(function(order) {
console.log(order)
});
// prints
cart: {object …}
couponDiscount: 0
customerGroupDiscount: 0
customerGroupVolumeDiscount: 0
discount: 0
handlingFee: 0
handlingFeeWithoutTax: 0
pricesIncludeTax: true
shipping: 1
shippingWithoutTax: 1
subtotal: 70
subtotalWithoutTax: 58.33
tax: 11.67
total: 71
totalWithoutTax: 59.33
volumeDiscount: 0
Ecwid.Cart.calculateTotal(function(order) {
if (!order)
alert('An error occurred while calculating the order!')
else
alert('Order total: ' + order.total);
});
Subscribe to the Ecwid.OnAPILoaded
JS API event to ensure availability of this function.
Fields:
Name | Type | Description |
---|---|---|
cart | <Cart> | The object describing the state of customer's cart. See Cart Object |
couponDiscount | integer | An absolute amount of coupon code discount for this order |
customerGroupDiscount | integer | An absolute amount of a discount based on customer group for this order |
customerGroupVolumeDiscount | integer | An absolute amount of a discount based on customer group and subtotal for this order |
discount | integer | An absolute amount of a total discount for this order |
handlingFee | integer | An absolute amount of handling fee applied to order |
handlingFeeWithoutTax | integer | An absolute amount of handling fee before applied tax |
pricesIncludeTax | boolean | true if store has "gross prices" setting enabled. false if store has "net prices" setting enabled |
shipping | integer | An absolute amount of shipping rate applied to order |
shippingWithoutTax | integer | An absolute amount of shipping rate before applied tax |
subtotal | integer | Order subtotal. Includes the sum of all products' cost in the order |
subtotalWithoutTax | integer | Order subtotal before applied tax |
tax | integer | An absolute amount of tax amount applied to order |
total | integer | Total amount of this order. Includes shipping, taxes, discounts, etc |
totalWithoutTax | integer | Total amount of this order before applied taxes |
volumeDiscount | integer | An absolute amount of a discount based on subtotal for this order |