@anker-in/shopify-react 0.1.1-beta.37 → 0.1.1-beta.39
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/dist/hooks/index.d.mts +13 -14
- package/dist/hooks/index.d.ts +13 -14
- package/dist/hooks/index.js +59 -34
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +59 -34
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +59 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -34
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +4 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +4 -1
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/hooks/index.mjs
CHANGED
|
@@ -990,6 +990,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
990
990
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
991
991
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
992
992
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
993
|
+
const { trigger: createCart3 } = useCreateCart();
|
|
993
994
|
const addToCart = useCallback(
|
|
994
995
|
async (_key, { arg }) => {
|
|
995
996
|
const {
|
|
@@ -1021,40 +1022,45 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1021
1022
|
if (lines.length === 0) {
|
|
1022
1023
|
return;
|
|
1023
1024
|
}
|
|
1024
|
-
|
|
1025
|
-
let resultCart =
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1025
|
+
let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
|
|
1026
|
+
let resultCart = null;
|
|
1027
|
+
if (!cartId) {
|
|
1028
|
+
resultCart = await createCart3({
|
|
1029
|
+
lines,
|
|
1030
|
+
buyerIdentity,
|
|
1031
|
+
discountCodes,
|
|
1032
|
+
customAttributes
|
|
1033
|
+
});
|
|
1034
|
+
} else {
|
|
1035
|
+
resultCart = await addCartLines2({
|
|
1036
|
+
cartId,
|
|
1037
|
+
lines
|
|
1038
|
+
});
|
|
1039
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
1040
|
+
if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
1041
|
+
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
1042
|
+
if (unapplicableCodes.length > 0) {
|
|
1043
|
+
if (onCodesInvalid) {
|
|
1044
|
+
const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
|
|
1045
|
+
if (handledCart) {
|
|
1046
|
+
resultCart = handledCart;
|
|
1047
|
+
}
|
|
1048
|
+
} else {
|
|
1049
|
+
await removeInvalidCodes({
|
|
1050
|
+
discountCodes: unapplicableCodes
|
|
1051
|
+
});
|
|
1042
1052
|
}
|
|
1043
|
-
} else {
|
|
1044
|
-
await removeInvalidCodes({
|
|
1045
|
-
discountCodes: unapplicableCodes
|
|
1046
|
-
});
|
|
1047
1053
|
}
|
|
1048
1054
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1055
|
+
if (resultCart && discountCodes && discountCodes.length > 0) {
|
|
1056
|
+
applyCartCodes({
|
|
1057
|
+
replaceExistingCodes,
|
|
1058
|
+
discountCodes
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
if (customAttributes && customAttributes.length > 0) {
|
|
1062
|
+
addCustomAttributes(customAttributes);
|
|
1063
|
+
}
|
|
1058
1064
|
}
|
|
1059
1065
|
if (withTrack) {
|
|
1060
1066
|
trackAddToCartGA({
|
|
@@ -1066,7 +1072,21 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1066
1072
|
performanceAdapter?.addToCartEnd();
|
|
1067
1073
|
return resultCart;
|
|
1068
1074
|
},
|
|
1069
|
-
[
|
|
1075
|
+
[
|
|
1076
|
+
client,
|
|
1077
|
+
locale,
|
|
1078
|
+
cartCookieAdapter,
|
|
1079
|
+
userAdapter,
|
|
1080
|
+
cart,
|
|
1081
|
+
withTrack,
|
|
1082
|
+
performanceAdapter,
|
|
1083
|
+
createCart3,
|
|
1084
|
+
addCartLines2,
|
|
1085
|
+
applyCartCodes,
|
|
1086
|
+
removeInvalidCodes,
|
|
1087
|
+
addCustomAttributes,
|
|
1088
|
+
config
|
|
1089
|
+
]
|
|
1070
1090
|
);
|
|
1071
1091
|
return useSWRMutation("add-to-cart", addToCart, swrOptions);
|
|
1072
1092
|
}
|
|
@@ -2398,7 +2418,10 @@ var createInitialValue = () => ({
|
|
|
2398
2418
|
freeShippingMethods: [],
|
|
2399
2419
|
paymentShippingMethods: [],
|
|
2400
2420
|
nddOverweight: false,
|
|
2401
|
-
tddOverweight: false
|
|
2421
|
+
tddOverweight: false,
|
|
2422
|
+
nddCoupon: void 0,
|
|
2423
|
+
tddCoupon: void 0,
|
|
2424
|
+
isLoadingCoupon: false
|
|
2402
2425
|
},
|
|
2403
2426
|
selectedPlusMemberProduct: null,
|
|
2404
2427
|
plusMemberProducts: [],
|
|
@@ -2443,7 +2466,9 @@ function usePlusAnnualProductVariant() {
|
|
|
2443
2466
|
}, [plusMemberProducts, plusAnnual]);
|
|
2444
2467
|
return plusAnnualProductVariant;
|
|
2445
2468
|
}
|
|
2446
|
-
var useAvailableDeliveryCoupon = ({
|
|
2469
|
+
var useAvailableDeliveryCoupon = ({
|
|
2470
|
+
profile
|
|
2471
|
+
}) => {
|
|
2447
2472
|
const { data: availableDeliveryCoupon, isLoading } = useSWR(
|
|
2448
2473
|
profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
|
|
2449
2474
|
async ([apiPath]) => {
|