@anker-in/shopify-react 0.1.1-beta.10 → 0.1.1-beta.12

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.
@@ -1319,7 +1319,7 @@ var useCartAttributes = ({
1319
1319
  return "new_user_login";
1320
1320
  }, [customer]);
1321
1321
  const memberAttributes = useMemo(() => {
1322
- return [
1322
+ const attributes = [
1323
1323
  {
1324
1324
  key: "_token",
1325
1325
  value: profile?.token
@@ -1338,8 +1338,19 @@ var useCartAttributes = ({
1338
1338
  {
1339
1339
  key: "_is_login",
1340
1340
  value: profile?.token ? "true" : "false"
1341
+ },
1342
+ {
1343
+ key: "_last_url",
1344
+ value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
1341
1345
  }
1342
1346
  ];
1347
+ if (profile?.token) {
1348
+ attributes.push({
1349
+ key: "_login_user",
1350
+ value: "1"
1351
+ });
1352
+ }
1353
+ return attributes;
1343
1354
  }, [profile?.memberType, profile?.token, userType, hasPlusMember]);
1344
1355
  const functionAttributes = useMemo(() => {
1345
1356
  const hasFunctionEnvAttribute = cart?.lineItems.some(
@@ -2555,21 +2566,22 @@ function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
2555
2566
  var useUpdatePlusMemberDeliveryOptions = ({
2556
2567
  options
2557
2568
  }) => {
2558
- const { cart, mutateCart: mutate, metafieldIdentifiers } = useCartContext();
2569
+ const { cart: cartContextData, mutateCart, metafieldIdentifiers } = useCartContext();
2559
2570
  const { trigger: updateCartDeliveryOptions2, isMutating } = useUpdateCartDeliveryOptions(
2560
- mutate,
2571
+ mutateCart,
2561
2572
  metafieldIdentifiers
2562
2573
  );
2563
2574
  const handler = useCallback(
2564
2575
  async (_, { arg }) => {
2576
+ const currentCart = arg?.cart || cartContextData;
2565
2577
  const { deliveryData } = arg;
2566
- const firstDeliveryGroup = cart?.deliveryGroups?.[0];
2578
+ const firstDeliveryGroup = currentCart?.deliveryGroups?.[0];
2567
2579
  const deliveryGroupId = firstDeliveryGroup?.id;
2568
2580
  const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
2569
2581
  if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
2570
2582
  return null;
2571
2583
  }
2572
- const deliveryGroup = cart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
2584
+ const deliveryGroup = currentCart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
2573
2585
  const matchedOption = deliveryGroup?.deliveryOptions?.find(
2574
2586
  (option) => option?.code === selectedOptionCode
2575
2587
  );
@@ -2583,14 +2595,15 @@ var useUpdatePlusMemberDeliveryOptions = ({
2583
2595
  }
2584
2596
  ];
2585
2597
  const updatedCart = await updateCartDeliveryOptions2({
2586
- selectedDeliveryOptions: deliveryOptions
2598
+ selectedDeliveryOptions: deliveryOptions,
2599
+ cartId: currentCart?.id
2587
2600
  });
2588
- if (updatedCart && mutate) {
2589
- mutate(updatedCart);
2601
+ if (updatedCart && mutateCart) {
2602
+ mutateCart(updatedCart);
2590
2603
  }
2591
2604
  return updatedCart;
2592
2605
  },
2593
- [cart, updateCartDeliveryOptions2, mutate]
2606
+ [cartContextData, updateCartDeliveryOptions2, mutateCart]
2594
2607
  );
2595
2608
  return useSWRMutation("update-cart-delivery-options", handler, options);
2596
2609
  };
@@ -2613,48 +2626,12 @@ var usePlusMemberCheckoutCustomAttributes = ({
2613
2626
  deliveryData,
2614
2627
  product,
2615
2628
  variant,
2616
- customer,
2617
2629
  isShowShippingBenefits
2618
2630
  }) => {
2619
2631
  const { deliveryCustomData } = deliveryData || {};
2620
2632
  const { profile } = usePlusMemberContext();
2621
- const userType = useMemo(() => {
2622
- const customerInfo = customer;
2623
- if (!customerInfo) {
2624
- return "new_user_unlogin";
2625
- }
2626
- if (customer) {
2627
- const { orders = {} } = customer;
2628
- const edgesLength = orders?.edges?.length;
2629
- if (edgesLength === 1) {
2630
- return "old_user_orders_once";
2631
- } else if (edgesLength && edgesLength > 1) {
2632
- return "old_user_orders_twice";
2633
- }
2634
- }
2635
- return "new_user_login";
2636
- }, [customer]);
2637
2633
  return useMemo(() => {
2638
- const checkoutCustomAttributes = [
2639
- {
2640
- key: "_token",
2641
- value: profile?.token || ""
2642
- },
2643
- {
2644
- key: "_last_url",
2645
- value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2646
- },
2647
- {
2648
- key: "_user_type",
2649
- value: userType
2650
- }
2651
- ];
2652
- if (profile) {
2653
- checkoutCustomAttributes.push({
2654
- key: "_login_user",
2655
- value: "1"
2656
- });
2657
- }
2634
+ const checkoutCustomAttributes = [];
2658
2635
  if (deliveryCustomData) {
2659
2636
  checkoutCustomAttributes.push({
2660
2637
  key: "_checkout_delivery_custom",
@@ -2664,12 +2641,6 @@ var usePlusMemberCheckoutCustomAttributes = ({
2664
2641
  })
2665
2642
  });
2666
2643
  }
2667
- if (variant?.metafields?.presell) {
2668
- checkoutCustomAttributes.push({
2669
- key: "_presale",
2670
- value: "true"
2671
- });
2672
- }
2673
2644
  if (isShowShippingBenefits && !isShowShippingBenefits({ variant, product, setting: {} })) {
2674
2645
  checkoutCustomAttributes.push({
2675
2646
  key: "_hide_shipping",
@@ -2677,7 +2648,7 @@ var usePlusMemberCheckoutCustomAttributes = ({
2677
2648
  });
2678
2649
  }
2679
2650
  return checkoutCustomAttributes;
2680
- }, [deliveryCustomData, product, profile, userType, variant, isShowShippingBenefits]);
2651
+ }, [deliveryCustomData, product, profile, variant, isShowShippingBenefits]);
2681
2652
  };
2682
2653
  function useAutoRemovePlusMemberInCart({
2683
2654
  cart,