merchi_cart 0.0.4-c → 0.0.4-e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Cart.js +20 -25
- package/lib/CartAlert.js +14 -12
- package/lib/CartHeader.js +9 -9
- package/lib/CartProvider.js +157 -226
- package/lib/CartTotals.js +44 -44
- package/lib/MerchiSDK/constants/auto_assign_production_on_actions.js +1 -1
- package/lib/MerchiSDK/constants/call_to_actions.js +1 -1
- package/lib/MerchiSDK/constants/discount_types.js +1 -1
- package/lib/MerchiSDK/constants/domain_types.js +1 -1
- package/lib/MerchiSDK/constants/errors.js +1 -1
- package/lib/MerchiSDK/constants/event_types.js +1 -1
- package/lib/MerchiSDK/constants/field_types.js +1 -1
- package/lib/MerchiSDK/constants/input_types.js +1 -1
- package/lib/MerchiSDK/constants/inventory_statuses.js +1 -1
- package/lib/MerchiSDK/constants/invoice_types.js +1 -1
- package/lib/MerchiSDK/constants/item_types.js +1 -1
- package/lib/MerchiSDK/constants/job/drafting_status.js +1 -1
- package/lib/MerchiSDK/constants/job/payment_status.js +1 -1
- package/lib/MerchiSDK/constants/job/production_status.js +1 -1
- package/lib/MerchiSDK/constants/job/shipment_status.js +1 -1
- package/lib/MerchiSDK/constants/job/supply_chain_request_status.js +1 -1
- package/lib/MerchiSDK/constants/job_priorities.js +1 -1
- package/lib/MerchiSDK/constants/job_status.js +5 -5
- package/lib/MerchiSDK/constants/job_types.js +1 -1
- package/lib/MerchiSDK/constants/notification_sections.js +1 -1
- package/lib/MerchiSDK/constants/notification_types.js +1 -1
- package/lib/MerchiSDK/constants/notification_urgencies.js +1 -1
- package/lib/MerchiSDK/constants/payment_types.js +1 -1
- package/lib/MerchiSDK/constants/platform.js +5 -5
- package/lib/MerchiSDK/constants/product_types.js +1 -1
- package/lib/MerchiSDK/constants/rights.js +1 -1
- package/lib/MerchiSDK/constants/robots_meta_directives.js +1 -1
- package/lib/MerchiSDK/constants/roles.js +8 -14
- package/lib/MerchiSDK/constants/shipment_companies.js +1 -1
- package/lib/MerchiSDK/constants/shipment_services.js +1 -1
- package/lib/MerchiSDK/constants/system_roles.js +1 -1
- package/lib/MerchiSDK/constants/theme_foundations.js +1 -1
- package/lib/MerchiSDK/constants/theme_status.js +1 -1
- package/lib/MerchiSDK/constants/user_types.js +1 -1
- package/lib/MerchiSDK/constants/white_label_accessibilities.js +1 -1
- package/lib/MerchiSDK/cookie.js +3 -3
- package/lib/MerchiSDK/entities/address.js +22 -43
- package/lib/MerchiSDK/entities/assignment.js +28 -49
- package/lib/MerchiSDK/entities/automatic_payment_relationship.js +11 -32
- package/lib/MerchiSDK/entities/backup.js +6 -27
- package/lib/MerchiSDK/entities/bank.js +17 -38
- package/lib/MerchiSDK/entities/cart.js +31 -64
- package/lib/MerchiSDK/entities/cart_item.js +30 -51
- package/lib/MerchiSDK/entities/cart_shipment_group.js +9 -30
- package/lib/MerchiSDK/entities/cart_shipment_quote.js +13 -34
- package/lib/MerchiSDK/entities/category.js +14 -35
- package/lib/MerchiSDK/entities/company.js +88 -109
- package/lib/MerchiSDK/entities/company_invitation.js +13 -34
- package/lib/MerchiSDK/entities/component.js +33 -54
- package/lib/MerchiSDK/entities/component_tag.js +7 -28
- package/lib/MerchiSDK/entities/component_version.js +12 -33
- package/lib/MerchiSDK/entities/country_tax.js +21 -45
- package/lib/MerchiSDK/entities/discount.js +13 -34
- package/lib/MerchiSDK/entities/discount_group.js +11 -32
- package/lib/MerchiSDK/entities/domain.js +80 -101
- package/lib/MerchiSDK/entities/domain_invitation.js +14 -35
- package/lib/MerchiSDK/entities/domain_tag.js +15 -36
- package/lib/MerchiSDK/entities/draft.js +32 -65
- package/lib/MerchiSDK/entities/draft_comment.js +19 -40
- package/lib/MerchiSDK/entities/draft_template.js +15 -36
- package/lib/MerchiSDK/entities/email_address.js +10 -31
- package/lib/MerchiSDK/entities/email_counter.js +8 -29
- package/lib/MerchiSDK/entities/enrolled_domain.js +20 -44
- package/lib/MerchiSDK/entities/exchange_rate.js +9 -30
- package/lib/MerchiSDK/entities/file.js +59 -80
- package/lib/MerchiSDK/entities/internal_tag.js +17 -38
- package/lib/MerchiSDK/entities/inventory.js +19 -42
- package/lib/MerchiSDK/entities/inventory_unit_variation.js +12 -33
- package/lib/MerchiSDK/entities/invoice.js +57 -78
- package/lib/MerchiSDK/entities/item.js +18 -39
- package/lib/MerchiSDK/entities/job.js +117 -140
- package/lib/MerchiSDK/entities/job_comment.js +18 -39
- package/lib/MerchiSDK/entities/matching_inventory.js +11 -32
- package/lib/MerchiSDK/entities/menu.js +12 -33
- package/lib/MerchiSDK/entities/menu_item.js +12 -33
- package/lib/MerchiSDK/entities/notification.js +32 -53
- package/lib/MerchiSDK/entities/page.js +13 -34
- package/lib/MerchiSDK/entities/payment.js +25 -46
- package/lib/MerchiSDK/entities/payment_device.js +12 -33
- package/lib/MerchiSDK/entities/phone_number.js +14 -35
- package/lib/MerchiSDK/entities/product.js +153 -188
- package/lib/MerchiSDK/entities/production_comment.js +18 -39
- package/lib/MerchiSDK/entities/quote.js +70 -106
- package/lib/MerchiSDK/entities/quote_item.js +28 -49
- package/lib/MerchiSDK/entities/seo_domain_page.js +13 -34
- package/lib/MerchiSDK/entities/session.js +11 -32
- package/lib/MerchiSDK/entities/shipment.js +62 -83
- package/lib/MerchiSDK/entities/shipment_item.js +7 -28
- package/lib/MerchiSDK/entities/shipment_item_fulfillment.js +7 -28
- package/lib/MerchiSDK/entities/shipment_method.js +21 -42
- package/lib/MerchiSDK/entities/shipment_method_variation.js +15 -36
- package/lib/MerchiSDK/entities/short_url.js +14 -35
- package/lib/MerchiSDK/entities/subscription_plan.js +26 -47
- package/lib/MerchiSDK/entities/supply_domain.js +11 -32
- package/lib/MerchiSDK/entities/system_role.js +7 -28
- package/lib/MerchiSDK/entities/theme.js +89 -110
- package/lib/MerchiSDK/entities/theme_css_setting.js +10 -31
- package/lib/MerchiSDK/entities/user.js +151 -213
- package/lib/MerchiSDK/entities/user_company.js +11 -32
- package/lib/MerchiSDK/entities/variation.js +21 -42
- package/lib/MerchiSDK/entities/variation_field.js +61 -94
- package/lib/MerchiSDK/entities/variation_fields_option.js +40 -61
- package/lib/MerchiSDK/entities/variation_option.js +20 -41
- package/lib/MerchiSDK/entities/variations_group.js +15 -36
- package/lib/MerchiSDK/entity.js +534 -624
- package/lib/MerchiSDK/merchi.js +42 -53
- package/lib/MerchiSDK/request.js +47 -75
- package/lib/MerchiSDK/test_util.js +6 -10
- package/lib/MerchiSDK/toasts.js +12 -13
- package/lib/MerchiSDK/util/float.js +7 -19
- package/lib/MerchiSDK/util/query_string.js +4 -4
- package/lib/MerchiSDK/util/validation.js +2 -3
- package/lib/MerchiSDK/uuid.js +2 -2
- package/lib/buttons/Button.js +15 -15
- package/lib/buttons/ButtonBack.js +22 -25
- package/lib/buttons/ButtonClearCart.js +8 -9
- package/lib/buttons/ButtonInvoiceDownload.js +26 -61
- package/lib/buttons/ButtonNext.js +20 -25
- package/lib/buttons/ButtonNextDynamic.js +16 -18
- package/lib/buttons/ButtonPay.js +17 -13
- package/lib/buttons/ButtonShipmentTabNext.js +12 -13
- package/lib/buttons/index.js +13 -13
- package/lib/components/Alert.js +14 -12
- package/lib/components/CartBody.js +10 -8
- package/lib/components/CartClient.js +22 -17
- package/lib/components/CartFooter.js +9 -7
- package/lib/components/CartItemRow.js +58 -48
- package/lib/components/CartPaymentSettingsInvalid.js +3 -4
- package/lib/components/CartShipment.js +18 -13
- package/lib/components/CartTabContent.js +9 -7
- package/lib/components/CartTabPanel.js +15 -13
- package/lib/components/CartTableContainer.js +9 -7
- package/lib/components/Collapse.js +14 -22
- package/lib/components/LoadingTemplate.js +10 -7
- package/lib/components/NoCartItems.js +9 -9
- package/lib/components/ShipmentGroupCard.js +69 -52
- package/lib/components/Table.js +7 -4
- package/lib/components/Title.js +11 -9
- package/lib/components/containers.js +12 -11
- package/lib/components/index.js +30 -31
- package/lib/forms/FormNewCustomer.js +48 -76
- package/lib/forms/FormReturningCustomer.js +38 -58
- package/lib/forms/FormShipmentAddressAndNotes.js +42 -47
- package/lib/forms/FormSquarePayment.js +8 -9
- package/lib/forms/FormStripePayment.js +8 -9
- package/lib/forms/InputAcceptUserTermsAndConditions.js +12 -11
- package/lib/forms/InputError.js +11 -9
- package/lib/forms/InputSelect.js +34 -36
- package/lib/forms/InputText.js +38 -42
- package/lib/forms/InputsAddress.js +59 -69
- package/lib/index.js +6 -6
- package/lib/panels/PanelCartItems.js +14 -17
- package/lib/panels/PanelCartShipment.js +10 -13
- package/lib/panels/PanelClearCart.js +8 -7
- package/lib/panels/PanelClientCheckout.js +18 -17
- package/lib/panels/PanelEditCartItem.js +17 -22
- package/lib/panels/PanelPaymentSuccess.js +18 -16
- package/lib/panels/index.js +13 -13
- package/lib/slices/sliceCart.js +53 -56
- package/lib/slices/sliceCartAlert.js +11 -15
- package/lib/slices/sliceCartItem.js +11 -10
- package/lib/slices/sliceCartPayment.js +15 -16
- package/lib/slices/sliceCartShipment.js +23 -26
- package/lib/slices/sliceFormReturningCustomer.js +7 -7
- package/lib/slices/sliceNewCustomerForm.js +6 -6
- package/lib/square/SquareCard.js +16 -18
- package/lib/square/actions.js +24 -46
- package/lib/square/slices/reducersSquare.js +6 -6
- package/lib/square/slices/sliceSquareAlerts.js +10 -16
- package/lib/square/slices/sliceSquareForm.js +10 -9
- package/lib/store.js +359 -565
- package/lib/stripe/StripeCardFields.js +43 -44
- package/lib/stripe/StripeCardForm.js +51 -109
- package/lib/stripe/StripePaymentButtons.js +35 -46
- package/lib/stripe/actions.js +75 -196
- package/lib/stripe/slices/sliceStripeAlerts.js +10 -16
- package/lib/stripe/slices/sliceStripeCardForm.js +6 -6
- package/lib/stripe/slices/sliceStripeForm.js +18 -17
- package/lib/stripe/utils.js +1 -1
- package/lib/tabs/CartNav.js +15 -24
- package/lib/tabs/NavTab.js +20 -19
- package/lib/utilities/address.js +32 -30
- package/lib/utilities/cart.js +33 -50
- package/lib/utilities/cookie.js +46 -129
- package/lib/utilities/currency.js +29 -25
- package/lib/utilities/helpers.js +41 -60
- package/lib/utilities/invoice.js +45 -114
- package/lib/utilities/product.js +5 -3
- package/lib/utilities/user.js +24 -62
- package/lib/utilities/variations.js +16 -14
- package/package.json +1 -1
package/lib/utilities/address.js
CHANGED
|
@@ -8,14 +8,14 @@ exports.addressInOneLine = addressInOneLine;
|
|
|
8
8
|
exports.geoSuggestResultAsNewAddress = geoSuggestResultAsNewAddress;
|
|
9
9
|
exports.makeAddress = makeAddress;
|
|
10
10
|
var _merchi = require("../MerchiSDK/merchi");
|
|
11
|
-
|
|
11
|
+
const merchi = new _merchi.Merchi();
|
|
12
12
|
function makeAddress(addressJson, makeDirty) {
|
|
13
|
-
|
|
13
|
+
const address = new merchi.Address();
|
|
14
14
|
return address.fromJson(addressJson, {
|
|
15
|
-
makeDirty
|
|
15
|
+
makeDirty
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
const isoCountries = {
|
|
19
19
|
AF: "Afghanistan",
|
|
20
20
|
AX: "Aland Islands",
|
|
21
21
|
AL: "Albania",
|
|
@@ -263,22 +263,24 @@ var isoCountries = {
|
|
|
263
263
|
ZW: "Zimbabwe"
|
|
264
264
|
};
|
|
265
265
|
function addressInOneLine(address) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
266
|
+
const a = address ? address : {};
|
|
267
|
+
const {
|
|
268
|
+
city,
|
|
269
|
+
country,
|
|
270
|
+
lineOne,
|
|
271
|
+
lineTwo,
|
|
272
|
+
postcode,
|
|
273
|
+
state
|
|
274
|
+
} = a;
|
|
275
|
+
const l1 = lineOne ? `${lineOne} ` : '';
|
|
276
|
+
const l2 = lineTwo ? `${lineTwo} ` : '';
|
|
277
|
+
const c = city ? `${city} ` : '';
|
|
278
|
+
const s = state ? `${state} ` : '';
|
|
279
|
+
const p = postcode ? `${postcode} ` : '';
|
|
280
|
+
const countryFull = country ? isoCountries[country] : '';
|
|
279
281
|
return l1 + l2 + c + s + p + countryFull;
|
|
280
282
|
}
|
|
281
|
-
|
|
283
|
+
const addressComponentsSettings = exports.addressComponentsSettings = {
|
|
282
284
|
administrative_area_level_1: 'short_name',
|
|
283
285
|
administrative_area_level_2: 'short_name',
|
|
284
286
|
country: 'short_name',
|
|
@@ -294,9 +296,9 @@ var addressComponentsSettings = exports.addressComponentsSettings = {
|
|
|
294
296
|
subpremise: 'short_name'
|
|
295
297
|
};
|
|
296
298
|
function geoSuggestResultAsNewAddress(resp) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
299
|
+
const addressComponents = resp && resp.gmaps ? resp.gmaps.address_components : null;
|
|
300
|
+
const name = resp && resp.gmaps && resp.gmaps.name;
|
|
301
|
+
const address = {
|
|
300
302
|
city: '',
|
|
301
303
|
country: '',
|
|
302
304
|
lineOne: name ? name : '',
|
|
@@ -304,15 +306,15 @@ function geoSuggestResultAsNewAddress(resp) {
|
|
|
304
306
|
postcode: '',
|
|
305
307
|
state: ''
|
|
306
308
|
};
|
|
307
|
-
|
|
309
|
+
let i;
|
|
308
310
|
if (addressComponents) {
|
|
309
311
|
for (i = 0; i < addressComponents.length; i++) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
const addrComponent = addressComponents[i];
|
|
313
|
+
const addrTypes = addrComponent.types;
|
|
314
|
+
const addrType = addrTypes.length > 0 ? addrTypes[0] : null;
|
|
315
|
+
const componentSetting = addrType ? addressComponentsSettings[addrType] : null;
|
|
314
316
|
if (componentSetting) {
|
|
315
|
-
|
|
317
|
+
const addressVal = addrComponent[componentSetting];
|
|
316
318
|
switch (addrType) {
|
|
317
319
|
case 'establishment':
|
|
318
320
|
case 'room':
|
|
@@ -321,12 +323,12 @@ function geoSuggestResultAsNewAddress(resp) {
|
|
|
321
323
|
case 'premise':
|
|
322
324
|
case 'subpremise':
|
|
323
325
|
case 'route':
|
|
324
|
-
|
|
325
|
-
address.lineOne = oldLineOne.includes(addressVal) ? oldLineOne :
|
|
326
|
+
const oldLineOne = address.lineOne;
|
|
327
|
+
address.lineOne = oldLineOne.includes(addressVal) ? oldLineOne : `${oldLineOne} ${addressVal}`;
|
|
326
328
|
break;
|
|
327
329
|
case 'locality':
|
|
328
330
|
case 'sublocality':
|
|
329
|
-
|
|
331
|
+
const oldCity = address.city ? `${address.city} ` : '';
|
|
330
332
|
address.city = oldCity + addressVal;
|
|
331
333
|
break;
|
|
332
334
|
case 'administrative_area_level_1':
|
package/lib/utilities/cart.js
CHANGED
|
@@ -12,88 +12,71 @@ exports.makeCartShipmentQuote = makeCartShipmentQuote;
|
|
|
12
12
|
exports.stripeIsValidAndActive = stripeIsValidAndActive;
|
|
13
13
|
var _merchi = require("../MerchiSDK/merchi");
|
|
14
14
|
var _company = require("./company");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
|
-
var merchi = new _merchi.Merchi();
|
|
20
|
-
var makeCart = exports.makeCart = function makeCart(json, makeDirty, cartToken) {
|
|
21
|
-
var merchi = new _merchi.Merchi();
|
|
15
|
+
const merchi = new _merchi.Merchi();
|
|
16
|
+
const makeCart = (json, makeDirty, cartToken) => {
|
|
17
|
+
const merchi = new _merchi.Merchi();
|
|
22
18
|
if (cartToken) merchi.cartToken = cartToken;
|
|
23
|
-
|
|
19
|
+
const cart = new merchi.Cart();
|
|
24
20
|
return cart.fromJson(json, {
|
|
25
|
-
makeDirty
|
|
21
|
+
makeDirty
|
|
26
22
|
});
|
|
27
23
|
};
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
exports.makeCart = makeCart;
|
|
25
|
+
const makeCartItem = (json, makeDirty, cartToken) => {
|
|
26
|
+
const merchi = new _merchi.Merchi();
|
|
30
27
|
if (cartToken) merchi.cartToken = cartToken;
|
|
31
|
-
|
|
28
|
+
const cartItem = new merchi.CartItem();
|
|
32
29
|
return cartItem.fromJson(json, {
|
|
33
|
-
makeDirty
|
|
30
|
+
makeDirty
|
|
34
31
|
});
|
|
35
32
|
};
|
|
33
|
+
exports.makeCartItem = makeCartItem;
|
|
36
34
|
function makeCartShipmentQuote(json, makeDirty) {
|
|
37
|
-
|
|
35
|
+
const cartShipmentQuote = new merchi.CartShipmentQuote();
|
|
38
36
|
return cartShipmentQuote.fromJson(json, {
|
|
39
|
-
makeDirty
|
|
37
|
+
makeDirty
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
function cartHasSelectedQuotes(cart) {
|
|
43
|
-
|
|
44
|
-
shipmentGroups =
|
|
41
|
+
const {
|
|
42
|
+
shipmentGroups = []
|
|
43
|
+
} = cart;
|
|
45
44
|
if (shipmentGroups.length) {
|
|
46
|
-
|
|
47
|
-
return !!g.selectedQuote;
|
|
48
|
-
});
|
|
45
|
+
const selected = shipmentGroups.filter(g => !!g.selectedQuote);
|
|
49
46
|
return selected.length === shipmentGroups.length;
|
|
50
47
|
}
|
|
51
48
|
return false;
|
|
52
49
|
}
|
|
53
|
-
function getCartShipmentGroupsAndQuotes(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
while (1) switch (_context.prev = _context.next) {
|
|
61
|
-
case 0:
|
|
62
|
-
query = [];
|
|
63
|
-
query.push(['cart_token', cart.token]);
|
|
64
|
-
return _context.abrupt("return", merchi.authenticatedFetch("/generate-cart-shipment-quotes/".concat(cart.id, "/"), {
|
|
65
|
-
method: 'GET',
|
|
66
|
-
query: query
|
|
67
|
-
}));
|
|
68
|
-
case 3:
|
|
69
|
-
case "end":
|
|
70
|
-
return _context.stop();
|
|
71
|
-
}
|
|
72
|
-
}, _callee);
|
|
73
|
-
}));
|
|
74
|
-
return _getCartShipmentGroupsAndQuotes.apply(this, arguments);
|
|
50
|
+
async function getCartShipmentGroupsAndQuotes(cart) {
|
|
51
|
+
const query = [];
|
|
52
|
+
query.push(['cart_token', cart.token]);
|
|
53
|
+
return merchi.authenticatedFetch(`/generate-cart-shipment-quotes/${cart.id}/`, {
|
|
54
|
+
method: 'GET',
|
|
55
|
+
query
|
|
56
|
+
});
|
|
75
57
|
}
|
|
76
58
|
function cartCompany(cart) {
|
|
77
59
|
return cart && cart.domain && cart.domain.company ? cart.domain.company : null;
|
|
78
60
|
}
|
|
79
61
|
function hasStripeLegacyAccount(cart) {
|
|
80
|
-
|
|
62
|
+
const company = cartCompany(cart);
|
|
81
63
|
return Boolean(company && (0, _company.companyStripePubKeyOrTestPubKey)(company));
|
|
82
64
|
}
|
|
83
65
|
function hasStripeConnectAccount(cart) {
|
|
84
|
-
|
|
66
|
+
const company = cartCompany(cart);
|
|
85
67
|
return Boolean(company && company.isStripeAccountEnabled);
|
|
86
68
|
}
|
|
87
69
|
function stripeIsValidAndActive(cart) {
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
const company = cartCompany(cart);
|
|
71
|
+
const hasStripe = hasStripeLegacyAccount(cart) || hasStripeConnectAccount(cart);
|
|
90
72
|
return Boolean(hasStripe && company && company.acceptStripe);
|
|
91
73
|
}
|
|
92
74
|
function cartRequiresShipment(cart) {
|
|
93
|
-
|
|
94
|
-
cartItems =
|
|
95
|
-
|
|
96
|
-
|
|
75
|
+
const {
|
|
76
|
+
cartItems = []
|
|
77
|
+
} = cart;
|
|
78
|
+
for (let i = 0; i < cartItems.length; i++) {
|
|
79
|
+
const item = cartItems[i];
|
|
97
80
|
if (item && item.product && item.product.needsShipping) {
|
|
98
81
|
return true;
|
|
99
82
|
}
|
package/lib/utilities/cookie.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,134 +8,52 @@ exports.getCookie = getCookie;
|
|
|
9
8
|
exports.setCartCookie = void 0;
|
|
10
9
|
var _lodash = require("lodash");
|
|
11
10
|
var _browserOrNode = require("browser-or-node");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
async function getCookie(name, defaultValue) {
|
|
12
|
+
if (!_browserOrNode.isBrowser) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
const searchPrefix = name + '=';
|
|
16
|
+
const cookies = document.cookie.split(';');
|
|
17
|
+
let i;
|
|
18
|
+
let cookie;
|
|
19
|
+
for (i = 0; i < cookies.length; ++i) {
|
|
20
|
+
cookie = cookies[i];
|
|
21
|
+
cookie = cookie.replace(/^\s*/, '');
|
|
22
|
+
if (cookie.indexOf(searchPrefix) === 0) {
|
|
23
|
+
return cookie.substring(searchPrefix.length, cookie.length);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if ((0, _lodash.isUndefined)(defaultValue)) {
|
|
27
|
+
throw 'no such cookie present';
|
|
28
|
+
} else {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
22
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
23
|
-
case 0:
|
|
24
|
-
if (_browserOrNode.isBrowser) {
|
|
25
|
-
_context2.next = 2;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
return _context2.abrupt("return", '');
|
|
29
|
-
case 2:
|
|
30
|
-
searchPrefix = name + '=';
|
|
31
|
-
cookies = document.cookie.split(';');
|
|
32
|
-
i = 0;
|
|
33
|
-
case 5:
|
|
34
|
-
if (!(i < cookies.length)) {
|
|
35
|
-
_context2.next = 13;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
cookie = cookies[i];
|
|
39
|
-
cookie = cookie.replace(/^\s*/, '');
|
|
40
|
-
if (!(cookie.indexOf(searchPrefix) === 0)) {
|
|
41
|
-
_context2.next = 10;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
return _context2.abrupt("return", cookie.substring(searchPrefix.length, cookie.length));
|
|
45
|
-
case 10:
|
|
46
|
-
++i;
|
|
47
|
-
_context2.next = 5;
|
|
48
|
-
break;
|
|
49
|
-
case 13:
|
|
50
|
-
if (!(0, _lodash.isUndefined)(defaultValue)) {
|
|
51
|
-
_context2.next = 17;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
throw 'no such cookie present';
|
|
55
|
-
case 17:
|
|
56
|
-
return _context2.abrupt("return", defaultValue);
|
|
57
|
-
case 18:
|
|
58
|
-
case "end":
|
|
59
|
-
return _context2.stop();
|
|
60
|
-
}
|
|
61
|
-
}, _callee2);
|
|
62
|
-
}));
|
|
63
|
-
return _getCookie.apply(this, arguments);
|
|
32
|
+
async function getCartCookie(domainId) {
|
|
33
|
+
const idAndToken = await getCookie(`cart-${domainId}`, null);
|
|
34
|
+
return idAndToken ? idAndToken.split(',') : null;
|
|
64
35
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
36
|
+
async function setSessionCookie(name, value, domain) {
|
|
37
|
+
if (!_browserOrNode.isBrowser) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let cookie = name + '=' + value;
|
|
41
|
+
if (!!domain) {
|
|
42
|
+
// remove port, if it exists
|
|
43
|
+
let n = domain.indexOf(':');
|
|
44
|
+
domain = domain.substring(0, n != -1 ? n : domain.length);
|
|
45
|
+
// remove trailing slash and path, if they exists
|
|
46
|
+
n = domain.indexOf('/');
|
|
47
|
+
domain = domain.substring(0, n != -1 ? n : domain.length);
|
|
48
|
+
cookie += '; Domain=' + domain;
|
|
49
|
+
} else {
|
|
50
|
+
cookie += '; Domain=' + '.' + location.hostname;
|
|
51
|
+
}
|
|
52
|
+
cookie += '; path=/';
|
|
53
|
+
document.cookie = cookie;
|
|
67
54
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
case 0:
|
|
74
|
-
_context3.next = 2;
|
|
75
|
-
return getCookie("cart-".concat(domainId), null);
|
|
76
|
-
case 2:
|
|
77
|
-
idAndToken = _context3.sent;
|
|
78
|
-
return _context3.abrupt("return", idAndToken ? idAndToken.split(',') : null);
|
|
79
|
-
case 4:
|
|
80
|
-
case "end":
|
|
81
|
-
return _context3.stop();
|
|
82
|
-
}
|
|
83
|
-
}, _callee3);
|
|
84
|
-
}));
|
|
85
|
-
return _getCartCookie.apply(this, arguments);
|
|
86
|
-
}
|
|
87
|
-
function setSessionCookie(_x4, _x5, _x6) {
|
|
88
|
-
return _setSessionCookie.apply(this, arguments);
|
|
89
|
-
}
|
|
90
|
-
function _setSessionCookie() {
|
|
91
|
-
_setSessionCookie = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(name, value, domain) {
|
|
92
|
-
var cookie, n;
|
|
93
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
94
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
if (_browserOrNode.isBrowser) {
|
|
97
|
-
_context4.next = 2;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
return _context4.abrupt("return");
|
|
101
|
-
case 2:
|
|
102
|
-
cookie = name + '=' + value;
|
|
103
|
-
if (!!domain) {
|
|
104
|
-
// remove port, if it exists
|
|
105
|
-
n = domain.indexOf(':');
|
|
106
|
-
domain = domain.substring(0, n != -1 ? n : domain.length);
|
|
107
|
-
// remove trailing slash and path, if they exists
|
|
108
|
-
n = domain.indexOf('/');
|
|
109
|
-
domain = domain.substring(0, n != -1 ? n : domain.length);
|
|
110
|
-
cookie += '; Domain=' + domain;
|
|
111
|
-
} else {
|
|
112
|
-
cookie += '; Domain=' + '.' + location.hostname;
|
|
113
|
-
}
|
|
114
|
-
cookie += '; path=/';
|
|
115
|
-
document.cookie = cookie;
|
|
116
|
-
case 6:
|
|
117
|
-
case "end":
|
|
118
|
-
return _context4.stop();
|
|
119
|
-
}
|
|
120
|
-
}, _callee4);
|
|
121
|
-
}));
|
|
122
|
-
return _setSessionCookie.apply(this, arguments);
|
|
123
|
-
}
|
|
124
|
-
var setCartCookie = exports.setCartCookie = /*#__PURE__*/function () {
|
|
125
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(storeId, cart, domain) {
|
|
126
|
-
var cookieValue;
|
|
127
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
128
|
-
while (1) switch (_context.prev = _context.next) {
|
|
129
|
-
case 0:
|
|
130
|
-
cookieValue = cart ? cart.id + ',' + cart.token : '';
|
|
131
|
-
_context.next = 3;
|
|
132
|
-
return setSessionCookie('cart-' + String(storeId), cookieValue, domain);
|
|
133
|
-
case 3:
|
|
134
|
-
case "end":
|
|
135
|
-
return _context.stop();
|
|
136
|
-
}
|
|
137
|
-
}, _callee);
|
|
138
|
-
}));
|
|
139
|
-
return function setCartCookie(_x7, _x8, _x9) {
|
|
140
|
-
return _ref.apply(this, arguments);
|
|
141
|
-
};
|
|
142
|
-
}();
|
|
55
|
+
const setCartCookie = async (storeId, cart, domain) => {
|
|
56
|
+
const cookieValue = cart ? cart.id + ',' + cart.token : '';
|
|
57
|
+
await setSessionCookie('cart-' + String(storeId), cookieValue, domain);
|
|
58
|
+
};
|
|
59
|
+
exports.setCartCookie = setCartCookie;
|
|
@@ -8,7 +8,7 @@ exports.cartItemCurrencyAndCost = cartItemCurrencyAndCost;
|
|
|
8
8
|
exports.currencyMap = void 0;
|
|
9
9
|
exports.currencyTaxAndCost = currencyTaxAndCost;
|
|
10
10
|
exports.formatCurrency = formatCurrency;
|
|
11
|
-
|
|
11
|
+
const currencyMap = exports.currencyMap = {
|
|
12
12
|
ALL: 'L',
|
|
13
13
|
AFN: '؋',
|
|
14
14
|
ARS: '$',
|
|
@@ -137,9 +137,9 @@ function formatCurrency(amount, options) {
|
|
|
137
137
|
--> '(£222.123)'
|
|
138
138
|
*/
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
let symbol;
|
|
141
|
+
let negative = false;
|
|
142
|
+
let result;
|
|
143
143
|
options = options || {};
|
|
144
144
|
options.currency = options.currency || 'AUD';
|
|
145
145
|
options.showCodeIfNoSymbol = options.showCodeIfNoSymbol || true;
|
|
@@ -161,7 +161,7 @@ function formatCurrency(amount, options) {
|
|
|
161
161
|
symbol += '(' + options.currency + ') ';
|
|
162
162
|
}
|
|
163
163
|
if (options.codeBeforeSymbol) {
|
|
164
|
-
symbol =
|
|
164
|
+
symbol = `(${options.currency}) ${symbol}`;
|
|
165
165
|
}
|
|
166
166
|
} else if (options.showCodeIfNoSymbol) {
|
|
167
167
|
symbol = options.currency;
|
|
@@ -185,45 +185,49 @@ function formatCurrency(amount, options) {
|
|
|
185
185
|
}
|
|
186
186
|
if (negative) {
|
|
187
187
|
if (options.financialNegative) {
|
|
188
|
-
result =
|
|
188
|
+
result = `(${result})`;
|
|
189
189
|
} else {
|
|
190
|
-
result =
|
|
190
|
+
result = `-${result}`;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
if (options.codeAfterAmount === true) {
|
|
194
|
-
result +=
|
|
194
|
+
result += ` (${options.currency})`;
|
|
195
195
|
}
|
|
196
196
|
return result;
|
|
197
197
|
}
|
|
198
198
|
function formatCountryTax(countryTax) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
const {
|
|
200
|
+
taxName,
|
|
201
|
+
taxPercent
|
|
202
|
+
} = countryTax;
|
|
203
|
+
return taxPercent > 0 ? ` inc ${taxName} (${taxPercent}%)` : '';
|
|
202
204
|
}
|
|
203
205
|
function calculateTotalWithTax(total, tax) {
|
|
204
|
-
|
|
206
|
+
let taxMultiplier = 1.0;
|
|
205
207
|
if (tax && tax.taxPercent() > 0) {
|
|
206
208
|
taxMultiplier += tax.taxPercent() / 100;
|
|
207
209
|
taxMultiplier = parseFloat(taxMultiplier.toFixed(2));
|
|
208
210
|
}
|
|
209
|
-
|
|
211
|
+
let grandTotal = total * taxMultiplier;
|
|
210
212
|
return parseFloat(grandTotal.toFixed(2));
|
|
211
213
|
}
|
|
212
214
|
function cartItemCurrencyAndCost(cartItem) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
const {
|
|
216
|
+
currency,
|
|
217
|
+
subtotalCost,
|
|
218
|
+
taxType
|
|
219
|
+
} = cartItem;
|
|
220
|
+
const tax = taxType ? formatCountryTax(taxType) : '';
|
|
221
|
+
return `${currency} ${formatCurrency(subtotalCost, {
|
|
222
|
+
currency,
|
|
219
223
|
showCodeIfNoSymbol: false
|
|
220
|
-
})
|
|
224
|
+
})} ${tax}`;
|
|
221
225
|
}
|
|
222
226
|
function currencyTaxAndCost(currency, tax, theCost) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return
|
|
226
|
-
currency
|
|
227
|
+
const totalCost = calculateTotalWithTax(theCost, tax);
|
|
228
|
+
const _tax = tax ? formatCountryTax(tax) : '';
|
|
229
|
+
return `${currency} ${formatCurrency(totalCost, {
|
|
230
|
+
currency,
|
|
227
231
|
showCodeIfNoSymbol: false
|
|
228
|
-
})
|
|
232
|
+
})} ${_tax}`;
|
|
229
233
|
}
|