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