@anker-in/shopify-react 0.1.1-beta.38 → 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 +2 -7
- package/dist/hooks/index.d.ts +2 -7
- package/dist/hooks/index.js +52 -32
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +52 -32
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +52 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -32
- package/dist/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
|
}
|