@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/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
|
}
|