@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.d.mts
CHANGED
|
@@ -60,15 +60,10 @@ interface CreateCartInput {
|
|
|
60
60
|
declare function useCreateCart(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'create-cart', CreateCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "create-cart", CreateCartInput>;
|
|
61
61
|
|
|
62
62
|
interface AddCartLinesInput {
|
|
63
|
-
/** Cart ID (
|
|
64
|
-
cartId
|
|
63
|
+
/** Cart ID (required) */
|
|
64
|
+
cartId: string;
|
|
65
65
|
/** Lines to add */
|
|
66
66
|
lines: CartLineInput[];
|
|
67
|
-
/** Buyer identity for new cart */
|
|
68
|
-
buyerIdentity?: {
|
|
69
|
-
email?: string;
|
|
70
|
-
countryCode?: string;
|
|
71
|
-
};
|
|
72
67
|
}
|
|
73
68
|
/**
|
|
74
69
|
* Hook for adding lines to cart
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -60,15 +60,10 @@ interface CreateCartInput {
|
|
|
60
60
|
declare function useCreateCart(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'create-cart', CreateCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "create-cart", CreateCartInput>;
|
|
61
61
|
|
|
62
62
|
interface AddCartLinesInput {
|
|
63
|
-
/** Cart ID (
|
|
64
|
-
cartId
|
|
63
|
+
/** Cart ID (required) */
|
|
64
|
+
cartId: string;
|
|
65
65
|
/** Lines to add */
|
|
66
66
|
lines: CartLineInput[];
|
|
67
|
-
/** Buyer identity for new cart */
|
|
68
|
-
buyerIdentity?: {
|
|
69
|
-
email?: string;
|
|
70
|
-
countryCode?: string;
|
|
71
|
-
};
|
|
72
67
|
}
|
|
73
68
|
/**
|
|
74
69
|
* Hook for adding lines to cart
|
package/dist/hooks/index.js
CHANGED
|
@@ -999,6 +999,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
999
999
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
1000
1000
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
1001
1001
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
1002
|
+
const { trigger: createCart3 } = useCreateCart();
|
|
1002
1003
|
const addToCart = react.useCallback(
|
|
1003
1004
|
async (_key, { arg }) => {
|
|
1004
1005
|
const {
|
|
@@ -1030,40 +1031,45 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1030
1031
|
if (lines.length === 0) {
|
|
1031
1032
|
return;
|
|
1032
1033
|
}
|
|
1033
|
-
|
|
1034
|
-
let resultCart =
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1034
|
+
let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
|
|
1035
|
+
let resultCart = null;
|
|
1036
|
+
if (!cartId) {
|
|
1037
|
+
resultCart = await createCart3({
|
|
1038
|
+
lines,
|
|
1039
|
+
buyerIdentity,
|
|
1040
|
+
discountCodes,
|
|
1041
|
+
customAttributes
|
|
1042
|
+
});
|
|
1043
|
+
} else {
|
|
1044
|
+
resultCart = await addCartLines2({
|
|
1045
|
+
cartId,
|
|
1046
|
+
lines
|
|
1047
|
+
});
|
|
1048
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
1049
|
+
if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
1050
|
+
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
1051
|
+
if (unapplicableCodes.length > 0) {
|
|
1052
|
+
if (onCodesInvalid) {
|
|
1053
|
+
const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
|
|
1054
|
+
if (handledCart) {
|
|
1055
|
+
resultCart = handledCart;
|
|
1056
|
+
}
|
|
1057
|
+
} else {
|
|
1058
|
+
await removeInvalidCodes({
|
|
1059
|
+
discountCodes: unapplicableCodes
|
|
1060
|
+
});
|
|
1051
1061
|
}
|
|
1052
|
-
} else {
|
|
1053
|
-
await removeInvalidCodes({
|
|
1054
|
-
discountCodes: unapplicableCodes
|
|
1055
|
-
});
|
|
1056
1062
|
}
|
|
1057
1063
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1064
|
+
if (resultCart && discountCodes && discountCodes.length > 0) {
|
|
1065
|
+
applyCartCodes({
|
|
1066
|
+
replaceExistingCodes,
|
|
1067
|
+
discountCodes
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
if (customAttributes && customAttributes.length > 0) {
|
|
1071
|
+
addCustomAttributes(customAttributes);
|
|
1072
|
+
}
|
|
1067
1073
|
}
|
|
1068
1074
|
if (withTrack) {
|
|
1069
1075
|
trackAddToCartGA({
|
|
@@ -1075,7 +1081,21 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1075
1081
|
performanceAdapter?.addToCartEnd();
|
|
1076
1082
|
return resultCart;
|
|
1077
1083
|
},
|
|
1078
|
-
[
|
|
1084
|
+
[
|
|
1085
|
+
client,
|
|
1086
|
+
locale,
|
|
1087
|
+
cartCookieAdapter,
|
|
1088
|
+
userAdapter,
|
|
1089
|
+
cart,
|
|
1090
|
+
withTrack,
|
|
1091
|
+
performanceAdapter,
|
|
1092
|
+
createCart3,
|
|
1093
|
+
addCartLines2,
|
|
1094
|
+
applyCartCodes,
|
|
1095
|
+
removeInvalidCodes,
|
|
1096
|
+
addCustomAttributes,
|
|
1097
|
+
config
|
|
1098
|
+
]
|
|
1079
1099
|
);
|
|
1080
1100
|
return useSWRMutation__default.default("add-to-cart", addToCart, swrOptions);
|
|
1081
1101
|
}
|