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