@anker-in/shopify-react 0.1.1-beta.19 → 0.1.1-beta.20

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.
@@ -1,5 +1,5 @@
1
1
  import { createContext, useMemo, useContext, useState, useCallback, useEffect, useRef } from 'react';
2
- import { createShopifyClient, getCart, updateCartAttributes, updateCartLines, getProductsByHandles } from '@anker-in/shopify-sdk';
2
+ import { createShopifyClient, getCart, updateCartAttributes, updateCartLines, btoaID, getProductsByHandles, getLocalStorage, atobID } from '@anker-in/shopify-sdk';
3
3
  import Cookies5 from 'js-cookie';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
  import Decimal2 from 'decimal.js';
@@ -187,16 +187,6 @@ var getQuery = () => {
187
187
  }
188
188
  return theRequest;
189
189
  };
190
- function atobID(id) {
191
- if (id && typeof id === "string" && id.includes("/")) {
192
- return id.split("/").pop()?.split("?")?.shift();
193
- } else {
194
- return id;
195
- }
196
- }
197
- function btoaID(id, type = "ProductVariant") {
198
- return `gid://shopify/${type}/${id}`;
199
- }
200
190
  var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
201
191
  const isAllStoreVariant = main_product?.all_store_variant ?? false;
202
192
  const matchedList = cartData?.lineItems?.filter((line) => {
@@ -718,12 +708,10 @@ function useHasPlusMemberInCart({
718
708
  };
719
709
  }, [cart?.lineItems, plus_monthly_product, plus_annual_product]);
720
710
  }
721
-
722
- // src/hooks/cart/feature/use-cart-attributes.ts
723
711
  var getReferralAttributes = () => {
724
- const inviteCode = Cookies5.get("invite_code");
725
- const playModeId = Cookies5.get("playModeId");
726
- const popup = Cookies5.get("_popup");
712
+ const inviteCode = getLocalStorage("invite_code") || Cookies5.get("invite_code");
713
+ const playModeId = getLocalStorage("playModeId") || Cookies5.get("playModeId");
714
+ const popup = getLocalStorage("_popup") || Cookies5.get("_popup");
727
715
  if (inviteCode && playModeId) {
728
716
  return popup ? [
729
717
  { key: "_invite_code", value: inviteCode ? inviteCode : "" },
@@ -1215,8 +1203,14 @@ function CartProvider({
1215
1203
  );
1216
1204
  return result;
1217
1205
  }, [cart?.lineItems, scriptAutoFreeGift, functionAutoFreeGift]);
1206
+ const totalQuantity = useMemo(() => {
1207
+ const cartLinesCount = cart?.lineItems.reduce((acc, item) => acc + item.quantity, 0) || 0;
1208
+ const giftLinesCount = giftNeedAddToCartLines?.reduce((acc, item) => acc + (item.quantity || 1), 0) || 0;
1209
+ return cartLinesCount + giftLinesCount;
1210
+ }, [cart?.lineItems, giftNeedAddToCartLines]);
1218
1211
  const value = useMemo(
1219
1212
  () => ({
1213
+ totalQuantity,
1220
1214
  cart,
1221
1215
  isCartLoading,
1222
1216
  triggerFetch: fetchCart,
@@ -1244,6 +1238,7 @@ function CartProvider({
1244
1238
  }),
1245
1239
  [
1246
1240
  cart,
1241
+ totalQuantity,
1247
1242
  isCartLoading,
1248
1243
  fetchCart,
1249
1244
  mutateCart,