@anker-in/shopify-react 0.1.1-beta.39 → 0.1.1-beta.40
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 +19 -3
- package/dist/hooks/index.d.ts +19 -3
- package/dist/hooks/index.js +20 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +20 -8
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +20 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -801,11 +801,23 @@ function useAddCartLines(options) {
|
|
|
801
801
|
const { mutateCart, metafieldIdentifiers } = useCartContext();
|
|
802
802
|
const addLines = react.useCallback(
|
|
803
803
|
async (_key, { arg }) => {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
804
|
+
const { cartId, lines } = arg;
|
|
805
|
+
const id = cartId || cartCookieAdapter?.getCartId(locale);
|
|
806
|
+
let updatedCart;
|
|
807
|
+
if (!id) {
|
|
808
|
+
updatedCart = await shopifySdk.createCart(client, {
|
|
809
|
+
lines,
|
|
810
|
+
metafieldIdentifiers,
|
|
811
|
+
cookieAdapter: cartCookieAdapter
|
|
812
|
+
});
|
|
813
|
+
} else {
|
|
814
|
+
updatedCart = await shopifySdk.addCartLines(client, {
|
|
815
|
+
cartId: id,
|
|
816
|
+
lines,
|
|
817
|
+
metafieldIdentifiers,
|
|
818
|
+
cookieAdapter: cartCookieAdapter
|
|
819
|
+
});
|
|
820
|
+
}
|
|
809
821
|
if (updatedCart) {
|
|
810
822
|
const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
811
823
|
if (unApplicableCodes.length > 0) {
|
|
@@ -1112,7 +1124,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1112
1124
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
1113
1125
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
1114
1126
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
1115
|
-
const { trigger:
|
|
1127
|
+
const { trigger: createCart4 } = useCreateCart();
|
|
1116
1128
|
const addToCart = react.useCallback(
|
|
1117
1129
|
async (_key, { arg }) => {
|
|
1118
1130
|
const {
|
|
@@ -1147,7 +1159,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1147
1159
|
let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
|
|
1148
1160
|
let resultCart = null;
|
|
1149
1161
|
if (!cartId) {
|
|
1150
|
-
resultCart = await
|
|
1162
|
+
resultCart = await createCart4({
|
|
1151
1163
|
lines,
|
|
1152
1164
|
buyerIdentity,
|
|
1153
1165
|
discountCodes,
|
|
@@ -1202,7 +1214,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
1202
1214
|
cart,
|
|
1203
1215
|
withTrack,
|
|
1204
1216
|
performanceAdapter,
|
|
1205
|
-
|
|
1217
|
+
createCart4,
|
|
1206
1218
|
addCartLines2,
|
|
1207
1219
|
applyCartCodes,
|
|
1208
1220
|
removeInvalidCodes,
|