Search.../

estimateCurrentCartTotals( )

Estimates the current cart's price totals (including tax), based on a selected carrier service, shipping address, and billing information.

Description

The estimateCurrentCartTotals() 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 estimateCurrentCartTotals(options: EstimateCurrentCartTotalsOptions): Promise<EstimateTotalsResponse>

estimateCurrentCartTotals Parameters

NAME
TYPE
DESCRIPTION
options
Optional
EstimateCurrentCartTotalsOptions

Total estimation options.

Returns

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 the current cart's totals

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