Search.../

estimateTotals( )

Estimates the subtotal and total for current site visitor’s cart. Totals include tax and are based on the selected carrier service, shipping address, and billing information.

Description

The estimateTotals() function returns a Promise that resolves when the estimated totals are generated.

Note: Not passing any options properties will only estimate the cart items price totals.

Syntax

function estimateTotals(_id: string, options: EstimateTotalsOptions): Promise<EstimateTotalsResponse>

estimateTotals Parameters

NAME
TYPE
DESCRIPTION
_id
string

Cart ID.

options
Optional
EstimateTotalsOptions

Total estimation options.

Returns

Fulfilled - Cart's estimated totals.

Return Type:

Promise<
EstimateTotalsResponse
>
NAME
TYPE
DESCRIPTION
additionalFees
Array<
AdditionalFee
>

Additional fees

appliedDiscounts
Array<
AppliedDiscount
>

Applied discounts.

calculatedLineItems
Array<
CalculatedLineItem
>

Calculated line items.

calculationErrors
CalculationErrors

Calculation errors.

cart
Cart

Cart.

currency
string

Currency used for pricing in this store.

giftCard
GiftCard

Applied gift card.

membershipOptions
MembershipOptions

Information about valid and invalid memberships, and which ones are selected for usage.

payLater
PriceSummary

Remaining amount for the order to be fully paid.

payNow
PriceSummary

Minimal amount to pay in order to place the order.

priceSummary
PriceSummary

Price summary.

shippingInfo
ShippingInformation

Shipping information.

taxSummary
TaxSummary

Tax summary.

violations
Array<
Violation
>

List of validation violations raised by the Validations Custom Extension SPI.

weightUnit
string

Weight measurement unit - defaults to site's weight unit. Supported values:

  • "KG"
  • "LB"

Was this helpful?

Estimate a cart's totals

Copy Code
1/*****************************************
2 * Backend code - my-backend-file.web.js *
3 ****************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { cart } from 'wix-ecom-backend';
7
8export const myEstimateTotalsFunction = webMethod(Permissions.Anyone, async (cartId, estimateOptions) => {
9 try {
10 const estimatedCartTotals = await cart.estimateTotals(cartId, estimateOptions);
11 console.log('Success! Cart totals estimated:', estimatedCartTotals);
12 return estimatedCartTotals;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myEstimateTotalsFunction } from 'backend/my-backend-file.web';
24
25// Sample cartId:
26const cartId = '96a61a4b-6b61-47d1-a039-0213a8230ccd';
27
28// Sample options object:
29const estimateOptions = {
30 "selectedShippingOption": {
31 "code": "standard_us_shipping"
32 },
33 "shippingAddress": {
34 "addressLine1": "235 West 23rd Street",
35 "addressLine2": "3rd floor",
36 "city": "New York",
37 "country": "US",
38 "postalCode": "10011",
39 "streetAddress": {
40 "name": "West 23rd Street",
41 "number": "235"
42 },
43 "subdivision": "US-NY"
44 },
45 "billingAddress": {
46 "addressLine1": "235 West 23rd Street",
47 "addressLine2": "3rd floor",
48 "city": "New York",
49 "country": "US",
50 "postalCode": "10011",
51 "streetAddress": {
52 "name": "West 23rd Street",
53 "number": "235"
54 },
55 "subdivision": "US-NY"
56 }
57};
58
59myEstimateTotalsFunction(cartId, estimateOptions)
60 .then((estimatedCartTotals) => {
61 const formattedShippingPrice = estimatedCartTotals.priceSummary.shipping.formattedAmount;
62 const estimatedCartTotal = estimatedCartTotals.priceSummary.total.formattedAmount;
63
64 console.log('Success! Cart totals estimated:', estimatedCartTotals);
65 return estimatedCartTotals;
66 })
67 .catch((error) => {
68 console.error(error);
69 // Handle the error
70 });
71
72/* Promise resolves to:
73 *
74 * {
75 * "cart": {
76 * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd",
77 * "lineItems": [
78 * {
79 * "_id": "00000000-0000-0000-0000-000000000001",
80 * "quantity": 5,
81 * "catalogReference": {
82 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
83 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
84 * },
85 * "productName": {
86 * "original": "Shirt",
87 * "translated": "Shirt"
88 * },
89 * "url": "https://example.wixsite.com",
90 * "price": {
91 * "amount": "10",
92 * "convertedAmount": "10",
93 * "formattedAmount": "€10.00",
94 * "formattedConvertedAmount": "€10.00"
95 * },
96 * "fullPrice": {
97 * "amount": "10",
98 * "convertedAmount": "10",
99 * "formattedAmount": "€10.00",
100 * "formattedConvertedAmount": "€10.00"
101 * },
102 * "priceBeforeDiscounts": {
103 * "amount": "10",
104 * "convertedAmount": "10",
105 * "formattedAmount": "€10.00",
106 * "formattedConvertedAmount": "€10.00"
107 * },
108 * "descriptionLines": [],
109 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
110 * "availability": {
111 * "status": "AVAILABLE"
112 * },
113 * "physicalProperties": {
114 * "sku": "364115376135191",
115 * "shippable": true
116 * },
117 * "couponScopes": [
118 * {
119 * "namespace": "stores",
120 * "group": {
121 * "name": "collection",
122 * "entityId": "00000000-000000-000000-000000000001"
123 * }
124 * },
125 * {
126 * "namespace": "stores",
127 * "group": {
128 * "name": "product",
129 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
130 * }
131 * }
132 * ],
133 * "itemType": {
134 * "preset": "PHYSICAL"
135 * },
136 * "paymentOption": "FULL_PAYMENT_ONLINE"
137 * }
138 * ],
139 * "buyerInfo": {
140 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
141 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
142 * },
143 * "currency": "EUR",
144 * "conversionCurrency": "EUR",
145 * "buyerLanguage": "en",
146 * "siteLanguage": "en",
147 * "taxIncludedInPrices": false,
148 * "weightUnit": "KG",
149 * "subtotal": {
150 * "amount": "50",
151 * "convertedAmount": "50",
152 * "formattedAmount": "€50.00",
153 * "formattedConvertedAmount": "€50.00"
154 * },
155 * "appliedDiscounts": [],
156 * "inSync": false,
157 * "_createdDate": "2022-05-16T12:04:01.244Z",
158 * "_updatedDate": "2022-05-23T11:55:30.023Z"
159 * },
160 * "calculatedLineItems": [
161 * {
162 * "lineItemId": "00000000-0000-0000-0000-000000000001",
163 * "pricesBreakdown": {
164 * "totalPriceAfterTax": {
165 * "amount": "50.00",
166 * "convertedAmount": "50.00",
167 * "formattedAmount": "€50.00",
168 * "formattedConvertedAmount": "€50.00"
169 * },
170 * "totalPriceBeforeTax": {
171 * "amount": "50.00",
172 * "convertedAmount": "50.00",
173 * "formattedAmount": "€50.00",
174 * "formattedConvertedAmount": "€50.00"
175 * },
176 * "taxDetails": {
177 * "taxableAmount": {
178 * "amount": "50.00",
179 * "convertedAmount": "50.00",
180 * "formattedAmount": "€50.00",
181 * "formattedConvertedAmount": "€50.00"
182 * },
183 * "taxRate": "0.0",
184 * "totalTax": {
185 * "amount": "0.0",
186 * "convertedAmount": "0.0",
187 * "formattedAmount": "€0.00",
188 * "formattedConvertedAmount": "€0.00"
189 * },
190 * "rateBreakdown": []
191 * },
192 * "totalDiscount": {
193 * "amount": "0",
194 * "convertedAmount": "0",
195 * "formattedAmount": "€0.00",
196 * "formattedConvertedAmount": "€0.00"
197 * },
198 * "price": {
199 * "amount": "10.00",
200 * "convertedAmount": "10.00",
201 * "formattedAmount": "€10.00",
202 * "formattedConvertedAmount": "€10.00"
203 * },
204 * "priceBeforeDiscounts": {
205 * "amount": "10.00",
206 * "convertedAmount": "",
207 * "formattedAmount": "",
208 * "formattedConvertedAmount": ""
209 * }
210 * },
211 * "paymentOption": "FULL_PAYMENT_ONLINE"
212 * }
213 * ],
214 * "priceSummary": {
215 * "subtotal": {
216 * "amount": "50.00",
217 * "convertedAmount": "50.00",
218 * "formattedAmount": "€50.00",
219 * "formattedConvertedAmount": "€50.00"
220 * },
221 * "shipping": {
222 * "amount": "10.0",
223 * "convertedAmount": "10.0",
224 * "formattedAmount": "€10.00",
225 * "formattedConvertedAmount": "€10.00"
226 * },
227 * "tax": {
228 * "amount": "0.0",
229 * "convertedAmount": "0.0",
230 * "formattedAmount": "€0.00",
231 * "formattedConvertedAmount": "€0.00"
232 * },
233 * "discount": {
234 * "amount": "0",
235 * "convertedAmount": "0",
236 * "formattedAmount": "€0.00",
237 * "formattedConvertedAmount": "€0.00"
238 * },
239 * "total": {
240 * "amount": "60.00",
241 * "convertedAmount": "60.00",
242 * "formattedAmount": "€60.00",
243 * "formattedConvertedAmount": "€60.00"
244 * }
245 * },
246 * "shippingInfo": {
247 * "region": {
248 * "_id": "009fbe5d-89d3-7825-cbbf-1aab4d908b73",
249 * "name": "USA shipping"
250 * },
251 * "selectedCarrierServiceOption": {
252 * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5",
253 * "title": "Standard US Shipping",
254 * "logistics": {
255 * "deliveryTime": ""
256 * },
257 * "cost": {
258 * "totalPriceAfterTax": {
259 * "amount": "10.0",
260 * "convertedAmount": "10.0",
261 * "formattedAmount": "€10.00",
262 * "formattedConvertedAmount": "€10.00"
263 * },
264 * "totalPriceBeforeTax": {
265 * "amount": "10",
266 * "convertedAmount": "10",
267 * "formattedAmount": "€10.00",
268 * "formattedConvertedAmount": "€10.00"
269 * },
270 * "taxDetails": {
271 * "taxRate": "0.0",
272 * "totalTax": {
273 * "amount": "0.0",
274 * "convertedAmount": "0.0",
275 * "formattedAmount": "€0.00",
276 * "formattedConvertedAmount": "€0.00"
277 * },
278 * "rateBreakdown": []
279 * },
280 * "price": {
281 * "amount": "10",
282 * "convertedAmount": "10",
283 * "formattedAmount": "€10.00",
284 * "formattedConvertedAmount": "€10.00"
285 * }
286 * },
287 * "requestedShippingOption": false,
288 * "otherCharges": [],
289 * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc"
290 * },
291 * "carrierServiceOptions": [
292 * {
293 * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc",
294 * "shippingOptions": [
295 * {
296 * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5",
297 * "title": "Standard US Shipping",
298 * "logistics": {
299 * "deliveryTime": ""
300 * },
301 * "cost": {
302 * "price": {
303 * "amount": "10",
304 * "convertedAmount": "10",
305 * "formattedAmount": "€10.00",
306 * "formattedConvertedAmount": "€10.00"
307 * },
308 * "otherCharges": []
309 * }
310 * }
311 * ]
312 * }
313 * ]
314 * },
315 * "appliedDiscounts": [],
316 * "calculationErrors": {
317 * "orderValidationErrors": []
318 * },
319 * "weightUnit": "KG",
320 * "currency": "EUR",
321 * "payNow": {
322 * "subtotal": {
323 * "amount": "50.00",
324 * "convertedAmount": "50.00",
325 * "formattedAmount": "€50.00",
326 * "formattedConvertedAmount": "€50.00"
327 * },
328 * "shipping": {
329 * "amount": "10.0",
330 * "convertedAmount": "10.0",
331 * "formattedAmount": "€10.00",
332 * "formattedConvertedAmount": "€10.00"
333 * },
334 * "tax": {
335 * "amount": "0.0",
336 * "convertedAmount": "0.0",
337 * "formattedAmount": "€0.00",
338 * "formattedConvertedAmount": "€0.00"
339 * },
340 * "discount": {
341 * "amount": "0",
342 * "convertedAmount": "0",
343 * "formattedAmount": "€0.00",
344 * "formattedConvertedAmount": "€0.00"
345 * },
346 * "total": {
347 * "amount": "60.00",
348 * "convertedAmount": "60.00",
349 * "formattedAmount": "€60.00",
350 * "formattedConvertedAmount": "€60.00"
351 * }
352 * },
353 * "payLater": {
354 * "subtotal": {
355 * "amount": "0",
356 * "convertedAmount": "0",
357 * "formattedAmount": "€0.00",
358 * "formattedConvertedAmount": "€0.00"
359 * },
360 * "shipping": {
361 * "amount": "0",
362 * "convertedAmount": "0",
363 * "formattedAmount": "€0.00",
364 * "formattedConvertedAmount": "€0.00"
365 * },
366 * "tax": {
367 * "amount": "0",
368 * "convertedAmount": "0",
369 * "formattedAmount": "€0.00",
370 * "formattedConvertedAmount": "€0.00"
371 * },
372 * "discount": {
373 * "amount": "0",
374 * "convertedAmount": "0",
375 * "formattedAmount": "€0.00",
376 * "formattedConvertedAmount": "€0.00"
377 * },
378 * "total": {
379 * "amount": "0",
380 * "convertedAmount": "0",
381 * "formattedAmount": "€0.00",
382 * "formattedConvertedAmount": "€0.00"
383 * }
384 * },
385 * "membershipOptions": {
386 * "eligibleMemberships": [],
387 * "invalidMemberships": [],
388 * "selectedMemberships": []
389 * }
390 * }
391 *
392 */