@anker-in/shopify-react 1.1.2 → 1.2.0-beta.1
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 +39 -44
- package/dist/hooks/index.d.ts +39 -44
- package/dist/hooks/index.js +347 -92
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +340 -93
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +436 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +425 -116
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +26 -14
- package/dist/provider/index.d.ts +26 -14
- package/dist/provider/index.js +155 -32
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +155 -32
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-CMMWxyUF.d.mts → types-C4qc-wG4.d.mts} +167 -7
- package/dist/{types-CMMWxyUF.d.ts → types-C4qc-wG4.d.ts} +167 -7
- package/package.json +4 -4
|
@@ -4,7 +4,8 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.mjs';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import {
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-C4qc-wG4.mjs';
|
|
8
|
+
import 'decimal.js';
|
|
8
9
|
|
|
9
10
|
interface ShopifyContextValue {
|
|
10
11
|
client: ShopifyClient;
|
|
@@ -48,6 +49,12 @@ type LoadingState = {
|
|
|
48
49
|
listingAutoCodeApplying: boolean;
|
|
49
50
|
userCodeApplying: boolean;
|
|
50
51
|
};
|
|
52
|
+
type AppContext = {
|
|
53
|
+
/** Whether running in app */
|
|
54
|
+
isInApp?: boolean;
|
|
55
|
+
/** App name */
|
|
56
|
+
appName?: string;
|
|
57
|
+
};
|
|
51
58
|
interface CartContextValue {
|
|
52
59
|
/** Current cart data */
|
|
53
60
|
cart: NormalizedCart | undefined;
|
|
@@ -91,10 +98,10 @@ interface CartContextValue {
|
|
|
91
98
|
calculatedAutoFreeGift?: any;
|
|
92
99
|
/** Gifts that need to be added to cart */
|
|
93
100
|
giftNeedAddToCartLines: any[];
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
101
|
+
/** Function auto free gift config */
|
|
102
|
+
functionAutoFreeGiftConfig?: any;
|
|
103
|
+
/** Script auto free gift config */
|
|
104
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
98
105
|
/** Metafield identifiers */
|
|
99
106
|
metafieldIdentifiers?: {
|
|
100
107
|
variant: HasMetafieldsIdentifier[];
|
|
@@ -106,17 +113,19 @@ interface CartContextValue {
|
|
|
106
113
|
customer?: any;
|
|
107
114
|
/** Plus member settings */
|
|
108
115
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
116
|
+
/** App context */
|
|
117
|
+
appContext?: AppContext;
|
|
118
|
+
/** Auto remove free gifts options */
|
|
119
|
+
autoRemoveFreeGiftsOptions?: UseAutoRemoveFreeGiftsOptions;
|
|
109
120
|
}
|
|
110
121
|
interface CartProviderProps {
|
|
111
122
|
children: React__default.ReactNode;
|
|
112
123
|
/** SWR configuration options */
|
|
113
124
|
swrOptions?: SWRConfiguration<NormalizedCart | undefined, Error>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
/** Function gift configuration */
|
|
119
|
-
fnGiftConf?: any;
|
|
125
|
+
/** Function auto free gift configuration */
|
|
126
|
+
functionAutoFreeGiftConfig?: any;
|
|
127
|
+
/** Script auto free gift configuration */
|
|
128
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
120
129
|
/** User profile */
|
|
121
130
|
profile?: any;
|
|
122
131
|
/** Customer data */
|
|
@@ -130,6 +139,8 @@ interface CartProviderProps {
|
|
|
130
139
|
};
|
|
131
140
|
/** Plus member settings */
|
|
132
141
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
142
|
+
/** App context */
|
|
143
|
+
appContext?: AppContext;
|
|
133
144
|
}
|
|
134
145
|
/**
|
|
135
146
|
* Cart Provider Component
|
|
@@ -141,7 +152,8 @@ interface CartProviderProps {
|
|
|
141
152
|
* <ShopifyProvider {...config}>
|
|
142
153
|
* <CartProvider
|
|
143
154
|
* locale="us"
|
|
144
|
-
*
|
|
155
|
+
* functionAutoFreeGiftConfig={functionConfig}
|
|
156
|
+
* scriptAutoFreeGiftConfig={scriptConfig}
|
|
145
157
|
* profile={profile}
|
|
146
158
|
* customer={customer}
|
|
147
159
|
* >
|
|
@@ -150,7 +162,7 @@ interface CartProviderProps {
|
|
|
150
162
|
* </ShopifyProvider>
|
|
151
163
|
* ```
|
|
152
164
|
*/
|
|
153
|
-
declare function CartProvider({ children,
|
|
165
|
+
declare function CartProvider({ children, functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, appContext, }: CartProviderProps): react_jsx_runtime.JSX.Element;
|
|
154
166
|
/**
|
|
155
167
|
* Hook to access cart context
|
|
156
168
|
*
|
|
@@ -175,4 +187,4 @@ declare function useCartContext(options: {
|
|
|
175
187
|
optional: true;
|
|
176
188
|
}): CartContextValue | null;
|
|
177
189
|
|
|
178
|
-
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
|
190
|
+
export { type AppContext, type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import {
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-C4qc-wG4.js';
|
|
8
|
+
import 'decimal.js';
|
|
8
9
|
|
|
9
10
|
interface ShopifyContextValue {
|
|
10
11
|
client: ShopifyClient;
|
|
@@ -48,6 +49,12 @@ type LoadingState = {
|
|
|
48
49
|
listingAutoCodeApplying: boolean;
|
|
49
50
|
userCodeApplying: boolean;
|
|
50
51
|
};
|
|
52
|
+
type AppContext = {
|
|
53
|
+
/** Whether running in app */
|
|
54
|
+
isInApp?: boolean;
|
|
55
|
+
/** App name */
|
|
56
|
+
appName?: string;
|
|
57
|
+
};
|
|
51
58
|
interface CartContextValue {
|
|
52
59
|
/** Current cart data */
|
|
53
60
|
cart: NormalizedCart | undefined;
|
|
@@ -91,10 +98,10 @@ interface CartContextValue {
|
|
|
91
98
|
calculatedAutoFreeGift?: any;
|
|
92
99
|
/** Gifts that need to be added to cart */
|
|
93
100
|
giftNeedAddToCartLines: any[];
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
101
|
+
/** Function auto free gift config */
|
|
102
|
+
functionAutoFreeGiftConfig?: any;
|
|
103
|
+
/** Script auto free gift config */
|
|
104
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
98
105
|
/** Metafield identifiers */
|
|
99
106
|
metafieldIdentifiers?: {
|
|
100
107
|
variant: HasMetafieldsIdentifier[];
|
|
@@ -106,17 +113,19 @@ interface CartContextValue {
|
|
|
106
113
|
customer?: any;
|
|
107
114
|
/** Plus member settings */
|
|
108
115
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
116
|
+
/** App context */
|
|
117
|
+
appContext?: AppContext;
|
|
118
|
+
/** Auto remove free gifts options */
|
|
119
|
+
autoRemoveFreeGiftsOptions?: UseAutoRemoveFreeGiftsOptions;
|
|
109
120
|
}
|
|
110
121
|
interface CartProviderProps {
|
|
111
122
|
children: React__default.ReactNode;
|
|
112
123
|
/** SWR configuration options */
|
|
113
124
|
swrOptions?: SWRConfiguration<NormalizedCart | undefined, Error>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
/** Function gift configuration */
|
|
119
|
-
fnGiftConf?: any;
|
|
125
|
+
/** Function auto free gift configuration */
|
|
126
|
+
functionAutoFreeGiftConfig?: any;
|
|
127
|
+
/** Script auto free gift configuration */
|
|
128
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
120
129
|
/** User profile */
|
|
121
130
|
profile?: any;
|
|
122
131
|
/** Customer data */
|
|
@@ -130,6 +139,8 @@ interface CartProviderProps {
|
|
|
130
139
|
};
|
|
131
140
|
/** Plus member settings */
|
|
132
141
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
142
|
+
/** App context */
|
|
143
|
+
appContext?: AppContext;
|
|
133
144
|
}
|
|
134
145
|
/**
|
|
135
146
|
* Cart Provider Component
|
|
@@ -141,7 +152,8 @@ interface CartProviderProps {
|
|
|
141
152
|
* <ShopifyProvider {...config}>
|
|
142
153
|
* <CartProvider
|
|
143
154
|
* locale="us"
|
|
144
|
-
*
|
|
155
|
+
* functionAutoFreeGiftConfig={functionConfig}
|
|
156
|
+
* scriptAutoFreeGiftConfig={scriptConfig}
|
|
145
157
|
* profile={profile}
|
|
146
158
|
* customer={customer}
|
|
147
159
|
* >
|
|
@@ -150,7 +162,7 @@ interface CartProviderProps {
|
|
|
150
162
|
* </ShopifyProvider>
|
|
151
163
|
* ```
|
|
152
164
|
*/
|
|
153
|
-
declare function CartProvider({ children,
|
|
165
|
+
declare function CartProvider({ children, functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, appContext, }: CartProviderProps): react_jsx_runtime.JSX.Element;
|
|
154
166
|
/**
|
|
155
167
|
* Hook to access cart context
|
|
156
168
|
*
|
|
@@ -175,4 +187,4 @@ declare function useCartContext(options: {
|
|
|
175
187
|
optional: true;
|
|
176
188
|
}): CartContextValue | null;
|
|
177
189
|
|
|
178
|
-
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
|
190
|
+
export { type AppContext, type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.js
CHANGED
|
@@ -714,6 +714,52 @@ var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttribute
|
|
|
714
714
|
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
715
715
|
);
|
|
716
716
|
};
|
|
717
|
+
function waitForGtagReady(timeout = 1e4) {
|
|
718
|
+
return new Promise((resolve, reject) => {
|
|
719
|
+
const start = Date.now();
|
|
720
|
+
function check() {
|
|
721
|
+
if (typeof window !== "undefined" && typeof window.gtag !== "undefined") {
|
|
722
|
+
resolve();
|
|
723
|
+
} else if (Date.now() - start > timeout) {
|
|
724
|
+
reject(new Error("GA4 gtag not loaded"));
|
|
725
|
+
} else {
|
|
726
|
+
setTimeout(check, 50);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
check();
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
var getGA4Data = async (measurementId = "G-R0BRMRK4CY") => {
|
|
733
|
+
try {
|
|
734
|
+
await waitForGtagReady();
|
|
735
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
736
|
+
setTimeout(() => {
|
|
737
|
+
resolve({ clientId: "", sessionId: "" });
|
|
738
|
+
}, 300);
|
|
739
|
+
});
|
|
740
|
+
const dataPromise = new Promise((resolve) => {
|
|
741
|
+
if (!window.gtag) {
|
|
742
|
+
resolve({ clientId: "", sessionId: "" });
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
window.gtag("get", measurementId, "client_id", (clientId) => {
|
|
746
|
+
window.gtag("get", measurementId, "session_id", (sessionId) => {
|
|
747
|
+
resolve({
|
|
748
|
+
clientId: clientId || "",
|
|
749
|
+
sessionId: sessionId || ""
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
return Promise.race([dataPromise, timeoutPromise]);
|
|
755
|
+
} catch (error) {
|
|
756
|
+
console.error("Failed to get GA4 data:", error);
|
|
757
|
+
return {
|
|
758
|
+
clientId: "",
|
|
759
|
+
sessionId: ""
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
};
|
|
717
763
|
var getReferralAttributes = () => {
|
|
718
764
|
const inviteCode = shopifySdk.getLocalStorage("inviteCode") || Cookies5__default.default.get("inviteCode");
|
|
719
765
|
const playModeId = shopifySdk.getLocalStorage("playModeId") || Cookies5__default.default.get("playModeId");
|
|
@@ -730,6 +776,19 @@ var getReferralAttributes = () => {
|
|
|
730
776
|
}
|
|
731
777
|
return [];
|
|
732
778
|
};
|
|
779
|
+
var getOperatingSystem = () => {
|
|
780
|
+
if (typeof window === "undefined" || typeof navigator === "undefined") {
|
|
781
|
+
return "Unknown";
|
|
782
|
+
}
|
|
783
|
+
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
784
|
+
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
|
|
785
|
+
return "IOS";
|
|
786
|
+
}
|
|
787
|
+
if (/android/i.test(userAgent)) {
|
|
788
|
+
return "Android";
|
|
789
|
+
}
|
|
790
|
+
return "Unknown";
|
|
791
|
+
};
|
|
733
792
|
var getUserType = (customer) => {
|
|
734
793
|
let userInfo = Cookies5__default.default.get("userInfo");
|
|
735
794
|
if (userInfo) {
|
|
@@ -751,12 +810,33 @@ var getUserType = (customer) => {
|
|
|
751
810
|
}
|
|
752
811
|
return "new_user_login";
|
|
753
812
|
};
|
|
754
|
-
function
|
|
813
|
+
function getGA4Attributes(ga4Data) {
|
|
814
|
+
if (!ga4Data?.clientId && !ga4Data?.sessionId) {
|
|
815
|
+
return [];
|
|
816
|
+
}
|
|
817
|
+
const attributes = [];
|
|
818
|
+
if (ga4Data.clientId) {
|
|
819
|
+
attributes.push({
|
|
820
|
+
key: "_ga4_client_id",
|
|
821
|
+
value: ga4Data.clientId
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
if (ga4Data.sessionId) {
|
|
825
|
+
attributes.push({
|
|
826
|
+
key: "_ga4_session_id",
|
|
827
|
+
value: ga4Data.sessionId
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
return attributes;
|
|
831
|
+
}
|
|
832
|
+
function getCartBasicAttributes({
|
|
755
833
|
profile,
|
|
756
834
|
customer,
|
|
757
835
|
cart,
|
|
758
836
|
memberType,
|
|
759
|
-
currentUrl = ""
|
|
837
|
+
currentUrl = "",
|
|
838
|
+
appContext,
|
|
839
|
+
buyPath
|
|
760
840
|
}) {
|
|
761
841
|
const userType = getUserType(customer);
|
|
762
842
|
const memberAttributes = [
|
|
@@ -783,12 +863,10 @@ function getCartAttributes({
|
|
|
783
863
|
value: "1"
|
|
784
864
|
});
|
|
785
865
|
}
|
|
786
|
-
const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
|
|
787
866
|
const functionAttributes = [
|
|
788
867
|
{
|
|
789
868
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
790
869
|
value: JSON.stringify({
|
|
791
|
-
discount_code: discountCodes,
|
|
792
870
|
user_tags: customer?.tags || []
|
|
793
871
|
})
|
|
794
872
|
}
|
|
@@ -796,26 +874,38 @@ function getCartAttributes({
|
|
|
796
874
|
const presellAttributes = [
|
|
797
875
|
{
|
|
798
876
|
key: "_presale",
|
|
799
|
-
value: cart?.lineItems
|
|
877
|
+
value: cart?.lineItems?.some((item) => item?.variant?.metafields?.presell === "presell")
|
|
800
878
|
}
|
|
801
879
|
];
|
|
802
880
|
const weightAttributes = [
|
|
803
881
|
{
|
|
804
882
|
key: "_weight",
|
|
805
|
-
value: cart?.lineItems
|
|
883
|
+
value: cart?.lineItems?.reduce((acc, item) => {
|
|
806
884
|
const itemWeight = new Decimal2__default.default(item.variant.weight ?? 0).times(item.quantity);
|
|
807
885
|
return new Decimal2__default.default(acc).plus(itemWeight).toNumber();
|
|
808
886
|
}, 0).toString()
|
|
809
|
-
},
|
|
810
|
-
{
|
|
811
|
-
key: "_app_source_name",
|
|
812
|
-
value: "dtc"
|
|
813
887
|
}
|
|
814
888
|
];
|
|
815
889
|
const trackingAttributes = [
|
|
816
890
|
{
|
|
817
891
|
key: "utm_params",
|
|
818
892
|
value: currentUrl
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
key: "_app_source_name",
|
|
896
|
+
value: appContext?.isInApp && appContext?.appName ? appContext.appName : "dtc"
|
|
897
|
+
},
|
|
898
|
+
{
|
|
899
|
+
key: "_operating_system",
|
|
900
|
+
value: getOperatingSystem()
|
|
901
|
+
},
|
|
902
|
+
{
|
|
903
|
+
key: "_cart_id",
|
|
904
|
+
value: cart?.id
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
key: "_buy_path",
|
|
908
|
+
value: buyPath
|
|
819
909
|
}
|
|
820
910
|
];
|
|
821
911
|
const commonAttributes = [
|
|
@@ -835,21 +925,41 @@ var useCartAttributes = ({
|
|
|
835
925
|
profile,
|
|
836
926
|
customer,
|
|
837
927
|
cart,
|
|
838
|
-
memberType
|
|
928
|
+
memberType,
|
|
929
|
+
appContext,
|
|
930
|
+
buyPath
|
|
839
931
|
}) => {
|
|
840
932
|
const [currentUrl, setCurrentUrl] = react.useState("");
|
|
933
|
+
const [ga4Data, setGa4Data] = react.useState(null);
|
|
841
934
|
react.useEffect(() => {
|
|
842
935
|
setCurrentUrl(window.location.href);
|
|
843
936
|
}, []);
|
|
937
|
+
react.useEffect(() => {
|
|
938
|
+
let isMounted = true;
|
|
939
|
+
getGA4Data().then((data) => {
|
|
940
|
+
if (isMounted) {
|
|
941
|
+
setGa4Data(data);
|
|
942
|
+
}
|
|
943
|
+
}).catch((error) => {
|
|
944
|
+
console.error("Failed to get GA4 data in useCartAttributes:", error);
|
|
945
|
+
});
|
|
946
|
+
return () => {
|
|
947
|
+
isMounted = false;
|
|
948
|
+
};
|
|
949
|
+
}, []);
|
|
844
950
|
const attributes = react.useMemo(() => {
|
|
845
|
-
|
|
951
|
+
const basicAttributes = getCartBasicAttributes({
|
|
846
952
|
profile,
|
|
847
953
|
customer,
|
|
848
954
|
cart,
|
|
849
955
|
memberType,
|
|
850
|
-
currentUrl
|
|
956
|
+
currentUrl,
|
|
957
|
+
appContext,
|
|
958
|
+
buyPath
|
|
851
959
|
});
|
|
852
|
-
|
|
960
|
+
const ga4Attributes = getGA4Attributes(ga4Data);
|
|
961
|
+
return [...basicAttributes, ...ga4Attributes];
|
|
962
|
+
}, [profile, customer, cart, memberType, currentUrl, appContext, buyPath, ga4Data]);
|
|
853
963
|
return react.useMemo(
|
|
854
964
|
() => ({
|
|
855
965
|
attributes
|
|
@@ -878,12 +988,9 @@ var useUpdateLineCodeAmountAttributes = ({
|
|
|
878
988
|
const codeDiscount = line.discountAllocations?.find(
|
|
879
989
|
(allocation) => mainProductDiscountCodes?.includes(allocation.code)
|
|
880
990
|
);
|
|
881
|
-
const hasFunctionEnvAttribute = line.customAttributes?.find(
|
|
882
|
-
(attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY
|
|
883
|
-
);
|
|
884
991
|
const functionEnvValue = getDiscountEnvAttributeValue(line.customAttributes);
|
|
885
992
|
const hasSameFunctionEnvAttribute = Number(functionEnvValue.discounted_amount) === Number(line.totalAmount);
|
|
886
|
-
if (!hasSameFunctionEnvAttribute &&
|
|
993
|
+
if (!hasSameFunctionEnvAttribute && !functionEnvValue.is_gift) {
|
|
887
994
|
attrNeedUpdate.push({
|
|
888
995
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
889
996
|
value: JSON.stringify({
|
|
@@ -1071,13 +1178,14 @@ var CartContext = react.createContext(null);
|
|
|
1071
1178
|
function CartProvider({
|
|
1072
1179
|
children,
|
|
1073
1180
|
// swrOptions,
|
|
1074
|
-
|
|
1075
|
-
|
|
1181
|
+
functionAutoFreeGiftConfig,
|
|
1182
|
+
scriptAutoFreeGiftConfig,
|
|
1076
1183
|
profile,
|
|
1077
1184
|
customer,
|
|
1078
1185
|
locale,
|
|
1079
1186
|
metafieldIdentifiers,
|
|
1080
|
-
memberSetting
|
|
1187
|
+
memberSetting,
|
|
1188
|
+
appContext
|
|
1081
1189
|
}) {
|
|
1082
1190
|
const { client, cartCookieAdapter } = useShopify();
|
|
1083
1191
|
const [customAttributes, setCustomAttributes] = react.useState([]);
|
|
@@ -1122,7 +1230,8 @@ function CartProvider({
|
|
|
1122
1230
|
profile,
|
|
1123
1231
|
customer,
|
|
1124
1232
|
cart,
|
|
1125
|
-
memberType: hasPlusMember ? "2" : String(profile?.memberType ?? 0)
|
|
1233
|
+
memberType: hasPlusMember ? "2" : String(profile?.memberType ?? 0),
|
|
1234
|
+
appContext
|
|
1126
1235
|
});
|
|
1127
1236
|
ahooks.useRequest(
|
|
1128
1237
|
() => {
|
|
@@ -1176,9 +1285,13 @@ function CartProvider({
|
|
|
1176
1285
|
},
|
|
1177
1286
|
[setCustomAttributes]
|
|
1178
1287
|
);
|
|
1179
|
-
const functionAutoFreeGiftResult = useCalcAutoFreeGift(
|
|
1288
|
+
const functionAutoFreeGiftResult = useCalcAutoFreeGift(
|
|
1289
|
+
cart,
|
|
1290
|
+
functionAutoFreeGiftConfig || [],
|
|
1291
|
+
customer
|
|
1292
|
+
);
|
|
1180
1293
|
const scriptAutoFreeGiftResult = useScriptAutoFreeGift({
|
|
1181
|
-
campaign:
|
|
1294
|
+
campaign: scriptAutoFreeGiftConfig,
|
|
1182
1295
|
_giveaway: CUSTOMER_SCRIPT_GIFT_KEY,
|
|
1183
1296
|
cart,
|
|
1184
1297
|
profile
|
|
@@ -1186,10 +1299,10 @@ function CartProvider({
|
|
|
1186
1299
|
const formattedScriptGifts = react.useMemo(() => {
|
|
1187
1300
|
return formatScriptAutoFreeGift({
|
|
1188
1301
|
scriptAutoFreeGiftResult,
|
|
1189
|
-
gradient_gifts:
|
|
1302
|
+
gradient_gifts: scriptAutoFreeGiftConfig,
|
|
1190
1303
|
locale
|
|
1191
1304
|
});
|
|
1192
|
-
}, [scriptAutoFreeGiftResult,
|
|
1305
|
+
}, [scriptAutoFreeGiftResult, scriptAutoFreeGiftConfig, locale]);
|
|
1193
1306
|
const formattedFunctionGifts = react.useMemo(() => {
|
|
1194
1307
|
return formatFunctionAutoFreeGift({
|
|
1195
1308
|
qualifyingGift: functionAutoFreeGiftResult?.qualifyingGift || null,
|
|
@@ -1237,6 +1350,12 @@ function CartProvider({
|
|
|
1237
1350
|
const giftLinesCount = giftNeedAddToCartLines?.reduce((acc, item) => acc + (item.quantity || 1), 0) || 0;
|
|
1238
1351
|
return cartLinesCount + giftLinesCount;
|
|
1239
1352
|
}, [cart?.lineItems, giftNeedAddToCartLines]);
|
|
1353
|
+
const autoRemoveFreeGiftsOptions = react.useMemo(() => {
|
|
1354
|
+
return {
|
|
1355
|
+
removeFunctionGifts: !!functionAutoFreeGiftConfig,
|
|
1356
|
+
removeScriptGifts: !!scriptAutoFreeGiftConfig
|
|
1357
|
+
};
|
|
1358
|
+
}, [functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig]);
|
|
1240
1359
|
const value = react.useMemo(
|
|
1241
1360
|
() => ({
|
|
1242
1361
|
totalQuantity,
|
|
@@ -1251,8 +1370,8 @@ function CartProvider({
|
|
|
1251
1370
|
customer,
|
|
1252
1371
|
isCodeChanging,
|
|
1253
1372
|
setIsCodeChanging,
|
|
1254
|
-
|
|
1255
|
-
|
|
1373
|
+
functionAutoFreeGiftConfig,
|
|
1374
|
+
scriptAutoFreeGiftConfig,
|
|
1256
1375
|
setLoadingState,
|
|
1257
1376
|
loadingState,
|
|
1258
1377
|
// function满赠
|
|
@@ -1265,7 +1384,9 @@ function CartProvider({
|
|
|
1265
1384
|
setScriptAutoFreeGift,
|
|
1266
1385
|
giftNeedAddToCartLines,
|
|
1267
1386
|
metafieldIdentifiers,
|
|
1268
|
-
memberSetting
|
|
1387
|
+
memberSetting,
|
|
1388
|
+
appContext,
|
|
1389
|
+
autoRemoveFreeGiftsOptions
|
|
1269
1390
|
}),
|
|
1270
1391
|
[
|
|
1271
1392
|
cart,
|
|
@@ -1277,8 +1398,8 @@ function CartProvider({
|
|
|
1277
1398
|
removeCustomAttributes,
|
|
1278
1399
|
locale,
|
|
1279
1400
|
isCodeChanging,
|
|
1280
|
-
|
|
1281
|
-
|
|
1401
|
+
functionAutoFreeGiftConfig,
|
|
1402
|
+
scriptAutoFreeGiftConfig,
|
|
1282
1403
|
loadingState,
|
|
1283
1404
|
// function满赠
|
|
1284
1405
|
functionAutoFreeGift,
|
|
@@ -1292,7 +1413,9 @@ function CartProvider({
|
|
|
1292
1413
|
metafieldIdentifiers,
|
|
1293
1414
|
customer,
|
|
1294
1415
|
profile,
|
|
1295
|
-
memberSetting
|
|
1416
|
+
memberSetting,
|
|
1417
|
+
appContext,
|
|
1418
|
+
autoRemoveFreeGiftsOptions
|
|
1296
1419
|
]
|
|
1297
1420
|
);
|
|
1298
1421
|
return /* @__PURE__ */ jsxRuntime.jsx(CartContext.Provider, { value, children });
|