@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/index.mjs
CHANGED
|
@@ -1104,6 +1104,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1104
1104
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
1105
1105
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
1106
1106
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
1107
|
+
const { trigger: createCart3 } = useCreateCart();
|
|
1107
1108
|
const addToCart = useCallback(
|
|
1108
1109
|
async (_key, { arg }) => {
|
|
1109
1110
|
const {
|
|
@@ -1135,40 +1136,45 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1135
1136
|
if (lines.length === 0) {
|
|
1136
1137
|
return;
|
|
1137
1138
|
}
|
|
1138
|
-
|
|
1139
|
-
let resultCart =
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1139
|
+
let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
|
|
1140
|
+
let resultCart = null;
|
|
1141
|
+
if (!cartId) {
|
|
1142
|
+
resultCart = await createCart3({
|
|
1143
|
+
lines,
|
|
1144
|
+
buyerIdentity,
|
|
1145
|
+
discountCodes,
|
|
1146
|
+
customAttributes
|
|
1147
|
+
});
|
|
1148
|
+
} else {
|
|
1149
|
+
resultCart = await addCartLines2({
|
|
1150
|
+
cartId,
|
|
1151
|
+
lines
|
|
1152
|
+
});
|
|
1153
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
1154
|
+
if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
1155
|
+
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
1156
|
+
if (unapplicableCodes.length > 0) {
|
|
1157
|
+
if (onCodesInvalid) {
|
|
1158
|
+
const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
|
|
1159
|
+
if (handledCart) {
|
|
1160
|
+
resultCart = handledCart;
|
|
1161
|
+
}
|
|
1162
|
+
} else {
|
|
1163
|
+
await removeInvalidCodes({
|
|
1164
|
+
discountCodes: unapplicableCodes
|
|
1165
|
+
});
|
|
1156
1166
|
}
|
|
1157
|
-
} else {
|
|
1158
|
-
await removeInvalidCodes({
|
|
1159
|
-
discountCodes: unapplicableCodes
|
|
1160
|
-
});
|
|
1161
1167
|
}
|
|
1162
1168
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1169
|
+
if (resultCart && discountCodes && discountCodes.length > 0) {
|
|
1170
|
+
applyCartCodes({
|
|
1171
|
+
replaceExistingCodes,
|
|
1172
|
+
discountCodes
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
if (customAttributes && customAttributes.length > 0) {
|
|
1176
|
+
addCustomAttributes(customAttributes);
|
|
1177
|
+
}
|
|
1172
1178
|
}
|
|
1173
1179
|
if (withTrack) {
|
|
1174
1180
|
trackAddToCartGA({
|
|
@@ -1180,7 +1186,21 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1180
1186
|
performanceAdapter?.addToCartEnd();
|
|
1181
1187
|
return resultCart;
|
|
1182
1188
|
},
|
|
1183
|
-
[
|
|
1189
|
+
[
|
|
1190
|
+
client,
|
|
1191
|
+
locale,
|
|
1192
|
+
cartCookieAdapter,
|
|
1193
|
+
userAdapter,
|
|
1194
|
+
cart,
|
|
1195
|
+
withTrack,
|
|
1196
|
+
performanceAdapter,
|
|
1197
|
+
createCart3,
|
|
1198
|
+
addCartLines2,
|
|
1199
|
+
applyCartCodes,
|
|
1200
|
+
removeInvalidCodes,
|
|
1201
|
+
addCustomAttributes,
|
|
1202
|
+
config
|
|
1203
|
+
]
|
|
1184
1204
|
);
|
|
1185
1205
|
return useSWRMutation("add-to-cart", addToCart, swrOptions);
|
|
1186
1206
|
}
|
|
@@ -2512,7 +2532,10 @@ var createInitialValue = () => ({
|
|
|
2512
2532
|
freeShippingMethods: [],
|
|
2513
2533
|
paymentShippingMethods: [],
|
|
2514
2534
|
nddOverweight: false,
|
|
2515
|
-
tddOverweight: false
|
|
2535
|
+
tddOverweight: false,
|
|
2536
|
+
nddCoupon: void 0,
|
|
2537
|
+
tddCoupon: void 0,
|
|
2538
|
+
isLoadingCoupon: false
|
|
2516
2539
|
},
|
|
2517
2540
|
selectedPlusMemberProduct: null,
|
|
2518
2541
|
plusMemberProducts: [],
|
|
@@ -2557,7 +2580,9 @@ function usePlusAnnualProductVariant() {
|
|
|
2557
2580
|
}, [plusMemberProducts, plusAnnual]);
|
|
2558
2581
|
return plusAnnualProductVariant;
|
|
2559
2582
|
}
|
|
2560
|
-
var useAvailableDeliveryCoupon = ({
|
|
2583
|
+
var useAvailableDeliveryCoupon = ({
|
|
2584
|
+
profile
|
|
2585
|
+
}) => {
|
|
2561
2586
|
const { data: availableDeliveryCoupon, isLoading } = useSWR(
|
|
2562
2587
|
profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
|
|
2563
2588
|
async ([apiPath]) => {
|