@anker-in/shopify-react 1.3.0-beta.3 → 1.3.0-beta.5
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 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +51 -23
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +52 -24
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +51 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -24
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +4 -4
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +3 -3
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/hooks/index.d.mts
CHANGED
|
@@ -920,7 +920,7 @@ interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
|
920
920
|
*/
|
|
921
921
|
declare function useAllProducts(options?: UseAllProductsOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
|
|
922
922
|
|
|
923
|
-
interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
923
|
+
interface UseProductsByHandlesOptions extends SWRConfiguration<(NormalizedProduct | undefined)[]> {
|
|
924
924
|
handles?: string[];
|
|
925
925
|
metafieldIdentifiers?: {
|
|
926
926
|
product: HasMetafieldsIdentifier[];
|
|
@@ -956,7 +956,7 @@ interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct
|
|
|
956
956
|
* }
|
|
957
957
|
* ```
|
|
958
958
|
*/
|
|
959
|
-
declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
|
|
959
|
+
declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<(NormalizedProduct | undefined)[], any, SWRConfiguration<(NormalizedProduct | undefined)[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<(NormalizedProduct | undefined)[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<(NormalizedProduct | undefined)[]>)> | undefined>;
|
|
960
960
|
|
|
961
961
|
/**
|
|
962
962
|
* useVariant Hook
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -920,7 +920,7 @@ interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
|
920
920
|
*/
|
|
921
921
|
declare function useAllProducts(options?: UseAllProductsOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
|
|
922
922
|
|
|
923
|
-
interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
923
|
+
interface UseProductsByHandlesOptions extends SWRConfiguration<(NormalizedProduct | undefined)[]> {
|
|
924
924
|
handles?: string[];
|
|
925
925
|
metafieldIdentifiers?: {
|
|
926
926
|
product: HasMetafieldsIdentifier[];
|
|
@@ -956,7 +956,7 @@ interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct
|
|
|
956
956
|
* }
|
|
957
957
|
* ```
|
|
958
958
|
*/
|
|
959
|
-
declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
|
|
959
|
+
declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<(NormalizedProduct | undefined)[], any, SWRConfiguration<(NormalizedProduct | undefined)[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<(NormalizedProduct | undefined)[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<(NormalizedProduct | undefined)[]>)> | undefined>;
|
|
960
960
|
|
|
961
961
|
/**
|
|
962
962
|
* useVariant Hook
|
package/dist/hooks/index.js
CHANGED
|
@@ -1165,6 +1165,26 @@ function useRemoveCartCodes(options) {
|
|
|
1165
1165
|
);
|
|
1166
1166
|
return useSWRMutation__default.default("remove-codes", removeCodes, options);
|
|
1167
1167
|
}
|
|
1168
|
+
function useUpdateCartLines(options) {
|
|
1169
|
+
const { client, locale, cartCookieAdapter } = useShopify();
|
|
1170
|
+
const { mutateCart, metafieldIdentifiers } = useCartContext();
|
|
1171
|
+
const updateLines = react.useCallback(
|
|
1172
|
+
async (_key, { arg }) => {
|
|
1173
|
+
const updatedCart = await shopifySdk.updateCartLines(client, {
|
|
1174
|
+
...arg,
|
|
1175
|
+
metafieldIdentifiers,
|
|
1176
|
+
cookieAdapter: cartCookieAdapter
|
|
1177
|
+
});
|
|
1178
|
+
if (updatedCart) {
|
|
1179
|
+
mutateCart(updatedCart);
|
|
1180
|
+
}
|
|
1181
|
+
console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
|
|
1182
|
+
return updatedCart;
|
|
1183
|
+
},
|
|
1184
|
+
[client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
|
|
1185
|
+
);
|
|
1186
|
+
return useSWRMutation__default.default("update-cart-lines", updateLines, options);
|
|
1187
|
+
}
|
|
1168
1188
|
var initSameLinesAttributes = ({
|
|
1169
1189
|
cart,
|
|
1170
1190
|
line
|
|
@@ -2326,6 +2346,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2326
2346
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
2327
2347
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
2328
2348
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
2349
|
+
const { trigger: updateCartLines3 } = useUpdateCartLines();
|
|
2329
2350
|
const { trigger: createCart4 } = useCreateCart({
|
|
2330
2351
|
updateCookie: true
|
|
2331
2352
|
});
|
|
@@ -2378,10 +2399,36 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2378
2399
|
// 初次加购时,就把所有 cart attributes 带上
|
|
2379
2400
|
});
|
|
2380
2401
|
} else {
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2402
|
+
const linesToUpdate = [];
|
|
2403
|
+
const linesToAddNew = lines.filter((lineToAdd) => {
|
|
2404
|
+
const existingLine = cart?.lineItems?.find(
|
|
2405
|
+
(item) => item.variant?.id === lineToAdd.merchandiseId
|
|
2406
|
+
);
|
|
2407
|
+
if (existingLine) {
|
|
2408
|
+
linesToUpdate.push({
|
|
2409
|
+
id: existingLine.id,
|
|
2410
|
+
quantity: existingLine.quantity + (lineToAdd.quantity || 1),
|
|
2411
|
+
attributes: lineToAdd.attributes || void 0
|
|
2412
|
+
});
|
|
2413
|
+
return false;
|
|
2414
|
+
}
|
|
2415
|
+
return true;
|
|
2384
2416
|
});
|
|
2417
|
+
if (linesToUpdate.length > 0) {
|
|
2418
|
+
resultCart = await updateCartLines3({
|
|
2419
|
+
cartId,
|
|
2420
|
+
lines: linesToUpdate
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
if (linesToAddNew.length > 0) {
|
|
2424
|
+
resultCart = await addCartLines2({
|
|
2425
|
+
cartId: resultCart?.id || cartId,
|
|
2426
|
+
lines: linesToAddNew
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
if (!resultCart) {
|
|
2430
|
+
resultCart = cart;
|
|
2431
|
+
}
|
|
2385
2432
|
console.log("npm addCartLines resultCart", resultCart);
|
|
2386
2433
|
if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
2387
2434
|
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
@@ -2442,6 +2489,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2442
2489
|
performanceAdapter,
|
|
2443
2490
|
createCart4,
|
|
2444
2491
|
addCartLines2,
|
|
2492
|
+
updateCartLines3,
|
|
2445
2493
|
applyCartCodes,
|
|
2446
2494
|
removeInvalidCodes,
|
|
2447
2495
|
addCustomAttributes,
|
|
@@ -2451,26 +2499,6 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2451
2499
|
);
|
|
2452
2500
|
return useSWRMutation__default.default("add-to-cart", addToCart, swrOptions);
|
|
2453
2501
|
}
|
|
2454
|
-
function useUpdateCartLines(options) {
|
|
2455
|
-
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2456
|
-
const { mutateCart, metafieldIdentifiers } = useCartContext();
|
|
2457
|
-
const updateLines = react.useCallback(
|
|
2458
|
-
async (_key, { arg }) => {
|
|
2459
|
-
const updatedCart = await shopifySdk.updateCartLines(client, {
|
|
2460
|
-
...arg,
|
|
2461
|
-
metafieldIdentifiers,
|
|
2462
|
-
cookieAdapter: cartCookieAdapter
|
|
2463
|
-
});
|
|
2464
|
-
if (updatedCart) {
|
|
2465
|
-
mutateCart(updatedCart);
|
|
2466
|
-
}
|
|
2467
|
-
console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
|
|
2468
|
-
return updatedCart;
|
|
2469
|
-
},
|
|
2470
|
-
[client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
|
|
2471
|
-
);
|
|
2472
|
-
return useSWRMutation__default.default("update-cart-lines", updateLines, options);
|
|
2473
|
-
}
|
|
2474
2502
|
function useUpdateCartAttributes({
|
|
2475
2503
|
mutate,
|
|
2476
2504
|
metafieldIdentifiers,
|