@anker-in/shopify-react 0.1.1-beta.22 → 0.1.1-beta.23
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 +245 -210
- package/dist/hooks/index.d.ts +245 -210
- package/dist/hooks/index.js +64 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +64 -3
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +64 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -3
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -2
- package/dist/provider/index.d.ts +1 -2
- package/dist/provider/index.js +1 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +1 -1
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-C1So3siD.d.mts → types-BSsb8OPm.d.mts} +1 -34
- package/dist/{types-C1So3siD.d.ts → types-BSsb8OPm.d.ts} +1 -34
- package/package.json +5 -5
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as swr_mutation from 'swr/mutation';
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
3
|
import * as _anker_in_shopify_sdk from '@anker-in/shopify-sdk';
|
|
4
|
-
import { CartLineInput, NormalizedCart,
|
|
5
|
-
import { A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig, d as PlusMemberShippingMethodConfig, e as PlusMemberSettingsMetafields, D as DeliveryPlusType, f as SelectedPlusMemberProduct, h as DeliveryData } from '../types-
|
|
6
|
-
export {
|
|
4
|
+
import { CartLineInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, NormalizedAttribute, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle } from '@anker-in/shopify-sdk';
|
|
5
|
+
import { U as UseAddToCartOptions, a as AddToCartInput, A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig, d as PlusMemberShippingMethodConfig, e as PlusMemberSettingsMetafields, D as DeliveryPlusType, f as SelectedPlusMemberProduct, h as DeliveryData } from '../types-BSsb8OPm.js';
|
|
6
|
+
export { g as DeliveryCustomData, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, c as PlusMemberShippingMethodMetafields, S as ShippingMethodMode } from '../types-BSsb8OPm.js';
|
|
7
7
|
import Decimal from 'decimal.js';
|
|
8
8
|
import * as swr from 'swr';
|
|
9
9
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
@@ -92,6 +92,244 @@ interface AddCartLinesInput {
|
|
|
92
92
|
*/
|
|
93
93
|
declare function useAddCartLines(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'add-cart-lines', AddCartLinesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "add-cart-lines", AddCartLinesInput>;
|
|
94
94
|
|
|
95
|
+
type AutoFreeGift = {
|
|
96
|
+
currentTier: {
|
|
97
|
+
amount: number;
|
|
98
|
+
gift?: NormalizedProductVariant;
|
|
99
|
+
};
|
|
100
|
+
nextTierGoal: {
|
|
101
|
+
amount: number;
|
|
102
|
+
gift?: NormalizedProductVariant;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
type DiscountLabel = {
|
|
106
|
+
cart_checkout_label: string;
|
|
107
|
+
product_label: string;
|
|
108
|
+
sold_out_label: string;
|
|
109
|
+
};
|
|
110
|
+
type AutoFreeGiftMainProduct = {
|
|
111
|
+
spend_money_type: number;
|
|
112
|
+
variant_id_list: string[];
|
|
113
|
+
all_store_variant: boolean;
|
|
114
|
+
};
|
|
115
|
+
type GiftProduct = {
|
|
116
|
+
spend_sum_money: number;
|
|
117
|
+
gift_type: number;
|
|
118
|
+
reward_list: {
|
|
119
|
+
get_unit: number;
|
|
120
|
+
variant_id: string;
|
|
121
|
+
bak_variant_id_list: null;
|
|
122
|
+
}[];
|
|
123
|
+
};
|
|
124
|
+
type AutoFreeGiftConfig = Config[];
|
|
125
|
+
type RuleCondition = {
|
|
126
|
+
with_special_url_params: string[];
|
|
127
|
+
without_special_url_params: string[];
|
|
128
|
+
with_user_tags: string[];
|
|
129
|
+
without_user_tags: string[];
|
|
130
|
+
};
|
|
131
|
+
type MainProductInfo = {
|
|
132
|
+
spend_money_type: SpendMoneyType;
|
|
133
|
+
variant_list: VariantItem[];
|
|
134
|
+
all_store_variant: boolean;
|
|
135
|
+
};
|
|
136
|
+
type Config = {
|
|
137
|
+
rule_id: number;
|
|
138
|
+
rule_type: RuleType;
|
|
139
|
+
discount_label: {
|
|
140
|
+
cart_checkout_label: string;
|
|
141
|
+
product_label: string;
|
|
142
|
+
sold_out_label: string;
|
|
143
|
+
};
|
|
144
|
+
frontend_labels: {
|
|
145
|
+
key: string;
|
|
146
|
+
label: string;
|
|
147
|
+
desc: string;
|
|
148
|
+
}[];
|
|
149
|
+
apply_unit: number;
|
|
150
|
+
rule_result: {
|
|
151
|
+
buy_rule_type: BuyRuleType;
|
|
152
|
+
spend_get_reward: {
|
|
153
|
+
main_product: MainProductInfo;
|
|
154
|
+
gift_product: GiftProductItem[];
|
|
155
|
+
};
|
|
156
|
+
buy_get_reward: {
|
|
157
|
+
main_product: MainProductInfo;
|
|
158
|
+
gift_product: GiftProductItem[] | null;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
rule_conditions?: RuleCondition[];
|
|
162
|
+
};
|
|
163
|
+
interface GiftTier {
|
|
164
|
+
spend_sum_money: number;
|
|
165
|
+
gift_type: number;
|
|
166
|
+
reward_list: RewardItem[];
|
|
167
|
+
}
|
|
168
|
+
interface RewardItem {
|
|
169
|
+
get_unit: number;
|
|
170
|
+
variant_list: VariantItem[];
|
|
171
|
+
}
|
|
172
|
+
interface VariantItem {
|
|
173
|
+
variant_id: string;
|
|
174
|
+
sku: string;
|
|
175
|
+
handle: string;
|
|
176
|
+
discount_value: number;
|
|
177
|
+
}
|
|
178
|
+
interface GiftProductItem {
|
|
179
|
+
spend_sum_money: number;
|
|
180
|
+
gift_type: number;
|
|
181
|
+
reward_list: RewardItem[];
|
|
182
|
+
}
|
|
183
|
+
declare enum RuleType {
|
|
184
|
+
AUTO_FREE_GIFT = 1,// 自动赠品
|
|
185
|
+
BUNDLE = 2,// 组合
|
|
186
|
+
VOLUME_DISCOUNT = 3,// 量价折扣
|
|
187
|
+
ORDER_DISCOUNT = 4,// 订单折扣
|
|
188
|
+
PRICE_DISCOUNT = 5
|
|
189
|
+
}
|
|
190
|
+
declare enum BuyRuleType {
|
|
191
|
+
BUY_GET_GIFT = 1,// 买赠
|
|
192
|
+
SPEND_GET_GIFT = 2
|
|
193
|
+
}
|
|
194
|
+
declare enum SpendMoneyType {
|
|
195
|
+
ORIGIN_PRICE = 1,// 原价
|
|
196
|
+
DISCOUNT_PRICE = 2
|
|
197
|
+
}
|
|
198
|
+
interface FunctionGiftResult {
|
|
199
|
+
qualifyingGift: FormattedGift | null;
|
|
200
|
+
nextTierGoal: GiftTier | null;
|
|
201
|
+
activeCampaign: Config | null;
|
|
202
|
+
isLoading: boolean;
|
|
203
|
+
giftProductsResult?: NormalizedProduct[] | [];
|
|
204
|
+
}
|
|
205
|
+
interface FormattedGift {
|
|
206
|
+
tier: GiftTier;
|
|
207
|
+
itemsToAdd: AutoFreeGiftCartLineInput[];
|
|
208
|
+
}
|
|
209
|
+
interface AutoFreeGiftCartLineInput {
|
|
210
|
+
variant: {
|
|
211
|
+
id: string;
|
|
212
|
+
handle: string;
|
|
213
|
+
sku: string;
|
|
214
|
+
};
|
|
215
|
+
quantity: number;
|
|
216
|
+
attributes: {
|
|
217
|
+
key: string;
|
|
218
|
+
value: string;
|
|
219
|
+
}[];
|
|
220
|
+
}
|
|
221
|
+
type AutoFreeGiftItem = {
|
|
222
|
+
line: NormalizedLineItem;
|
|
223
|
+
isSoldOut: boolean;
|
|
224
|
+
};
|
|
225
|
+
type AutoFreeGiftList = AutoFreeGiftItem[] | [];
|
|
226
|
+
|
|
227
|
+
declare enum OrderDiscountType {
|
|
228
|
+
PERCENTAGE = 1,// 百分比折扣
|
|
229
|
+
FIXED_AMOUNT = 2,// 固定金额折扣
|
|
230
|
+
REDUCE_PRICE = 3
|
|
231
|
+
}
|
|
232
|
+
declare enum OrderBasePriceType {
|
|
233
|
+
ORIGIN_PRICE = 1,// 原价
|
|
234
|
+
MIN_DISCOUNTED_PRICE = 2
|
|
235
|
+
}
|
|
236
|
+
type TieredDiscount = {
|
|
237
|
+
amount: number;
|
|
238
|
+
discount: number;
|
|
239
|
+
discount_type: OrderDiscountType;
|
|
240
|
+
};
|
|
241
|
+
type OrderDiscountConfig = {
|
|
242
|
+
rule_id: number;
|
|
243
|
+
rule_type: number;
|
|
244
|
+
rule_conditions?: RuleCondition[];
|
|
245
|
+
result_detail: {
|
|
246
|
+
main_product: {
|
|
247
|
+
variant_list: Array<{
|
|
248
|
+
variant_id: string;
|
|
249
|
+
sku: string;
|
|
250
|
+
handle: string;
|
|
251
|
+
}>;
|
|
252
|
+
all_store_variant: boolean;
|
|
253
|
+
skip_variants?: Array<{
|
|
254
|
+
variant_id: string;
|
|
255
|
+
sku: string;
|
|
256
|
+
handle: string;
|
|
257
|
+
}>;
|
|
258
|
+
};
|
|
259
|
+
order_discount_conf: {
|
|
260
|
+
base_price: OrderBasePriceType;
|
|
261
|
+
tiered_discounts: TieredDiscount[];
|
|
262
|
+
tiered_discounts_markets?: Record<string, TieredDiscount[]>;
|
|
263
|
+
is_reusable?: boolean;
|
|
264
|
+
min_quantity_items?: number;
|
|
265
|
+
max_apply_times_of_per_order?: number;
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
discount_label?: {
|
|
269
|
+
cart_checkout_label?: string;
|
|
270
|
+
product_label?: string;
|
|
271
|
+
sold_out_label?: string;
|
|
272
|
+
};
|
|
273
|
+
frontend_labels?: any[];
|
|
274
|
+
discount_combinations?: {
|
|
275
|
+
other_order_discounts?: boolean;
|
|
276
|
+
other_product_discounts?: boolean;
|
|
277
|
+
shipping_discounts?: boolean;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
declare enum PriceDiscountType {
|
|
282
|
+
PERCENTAGE = 1,// 百分比折扣
|
|
283
|
+
FIXED_AMOUNT = 2
|
|
284
|
+
}
|
|
285
|
+
declare enum PriceBasePriceType {
|
|
286
|
+
MIN_DISCOUNTED_PRICE = 1,// 最低折扣价
|
|
287
|
+
MIN_TOTAL_PRICE = 2
|
|
288
|
+
}
|
|
289
|
+
type PriceDiscountConfig = {
|
|
290
|
+
rule_id: number;
|
|
291
|
+
rule_type: number;
|
|
292
|
+
discount_type: PriceDiscountType;
|
|
293
|
+
discount_value: number;
|
|
294
|
+
base_price_type: PriceBasePriceType;
|
|
295
|
+
applicable_products: Array<{
|
|
296
|
+
product_id: string;
|
|
297
|
+
variant_id?: string;
|
|
298
|
+
}>;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Hook for adding items to cart with tracking support
|
|
303
|
+
*
|
|
304
|
+
* This is the enhanced version that includes:
|
|
305
|
+
* - Automatic cart creation if needed
|
|
306
|
+
* - Discount code validation
|
|
307
|
+
* - Google Analytics tracking
|
|
308
|
+
* - Facebook Pixel tracking
|
|
309
|
+
* - Invalid code handling
|
|
310
|
+
*
|
|
311
|
+
* @param options - Hook configuration
|
|
312
|
+
* @param swrOptions - SWR mutation configuration
|
|
313
|
+
* @returns SWR mutation with trigger function
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```tsx
|
|
317
|
+
* const { trigger, isMutating } = useAddToCart({ withTrack: true})
|
|
318
|
+
*
|
|
319
|
+
* await trigger({
|
|
320
|
+
* lineItems: [{
|
|
321
|
+
* variantId: 'gid://shopify/ProductVariant/123',
|
|
322
|
+
* quantity: 2
|
|
323
|
+
* }],
|
|
324
|
+
* gtmParams: {
|
|
325
|
+
* pageGroup: 'PDP',
|
|
326
|
+
* position: 'Add to Cart Button'
|
|
327
|
+
* }
|
|
328
|
+
* })
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
declare function useAddToCart({ withTrack }?: UseAddToCartOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, AddToCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, AddToCartInput>;
|
|
332
|
+
|
|
95
333
|
/**
|
|
96
334
|
* Hook for updating cart line quantities
|
|
97
335
|
*
|
|
@@ -291,138 +529,6 @@ interface UseBuyNowOptions {
|
|
|
291
529
|
*/
|
|
292
530
|
declare function useBuyNow({ withTrack }?: UseBuyNowOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, BuyNowInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, BuyNowInput>;
|
|
293
531
|
|
|
294
|
-
type AutoFreeGift = {
|
|
295
|
-
currentTier: {
|
|
296
|
-
amount: number;
|
|
297
|
-
gift?: NormalizedProductVariant;
|
|
298
|
-
};
|
|
299
|
-
nextTierGoal: {
|
|
300
|
-
amount: number;
|
|
301
|
-
gift?: NormalizedProductVariant;
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
type DiscountLabel = {
|
|
305
|
-
cart_checkout_label: string;
|
|
306
|
-
product_label: string;
|
|
307
|
-
sold_out_label: string;
|
|
308
|
-
};
|
|
309
|
-
type AutoFreeGiftMainProduct = {
|
|
310
|
-
spend_money_type: number;
|
|
311
|
-
variant_id_list: string[];
|
|
312
|
-
all_store_variant: boolean;
|
|
313
|
-
};
|
|
314
|
-
type GiftProduct = {
|
|
315
|
-
spend_sum_money: number;
|
|
316
|
-
gift_type: number;
|
|
317
|
-
reward_list: {
|
|
318
|
-
get_unit: number;
|
|
319
|
-
variant_id: string;
|
|
320
|
-
bak_variant_id_list: null;
|
|
321
|
-
}[];
|
|
322
|
-
};
|
|
323
|
-
type AutoFreeGiftConfig = Config[];
|
|
324
|
-
type RuleCondition = {
|
|
325
|
-
with_special_url_params: string[];
|
|
326
|
-
without_special_url_params: string[];
|
|
327
|
-
with_user_tags: string[];
|
|
328
|
-
without_user_tags: string[];
|
|
329
|
-
};
|
|
330
|
-
type MainProductInfo = {
|
|
331
|
-
spend_money_type: SpendMoneyType;
|
|
332
|
-
variant_list: VariantItem[];
|
|
333
|
-
all_store_variant: boolean;
|
|
334
|
-
};
|
|
335
|
-
type Config = {
|
|
336
|
-
rule_id: number;
|
|
337
|
-
rule_type: RuleType;
|
|
338
|
-
discount_label: {
|
|
339
|
-
cart_checkout_label: string;
|
|
340
|
-
product_label: string;
|
|
341
|
-
sold_out_label: string;
|
|
342
|
-
};
|
|
343
|
-
frontend_labels: {
|
|
344
|
-
key: string;
|
|
345
|
-
label: string;
|
|
346
|
-
desc: string;
|
|
347
|
-
}[];
|
|
348
|
-
apply_unit: number;
|
|
349
|
-
rule_result: {
|
|
350
|
-
buy_rule_type: BuyRuleType;
|
|
351
|
-
spend_get_reward: {
|
|
352
|
-
main_product: MainProductInfo;
|
|
353
|
-
gift_product: GiftProductItem[];
|
|
354
|
-
};
|
|
355
|
-
buy_get_reward: {
|
|
356
|
-
main_product: MainProductInfo;
|
|
357
|
-
gift_product: GiftProductItem[] | null;
|
|
358
|
-
};
|
|
359
|
-
};
|
|
360
|
-
rule_conditions?: RuleCondition[];
|
|
361
|
-
};
|
|
362
|
-
interface GiftTier {
|
|
363
|
-
spend_sum_money: number;
|
|
364
|
-
gift_type: number;
|
|
365
|
-
reward_list: RewardItem[];
|
|
366
|
-
}
|
|
367
|
-
interface RewardItem {
|
|
368
|
-
get_unit: number;
|
|
369
|
-
variant_list: VariantItem[];
|
|
370
|
-
}
|
|
371
|
-
interface VariantItem {
|
|
372
|
-
variant_id: string;
|
|
373
|
-
sku: string;
|
|
374
|
-
handle: string;
|
|
375
|
-
discount_value: number;
|
|
376
|
-
}
|
|
377
|
-
interface GiftProductItem {
|
|
378
|
-
spend_sum_money: number;
|
|
379
|
-
gift_type: number;
|
|
380
|
-
reward_list: RewardItem[];
|
|
381
|
-
}
|
|
382
|
-
declare enum RuleType {
|
|
383
|
-
AUTO_FREE_GIFT = 1,// 自动赠品
|
|
384
|
-
BUNDLE = 2,// 组合
|
|
385
|
-
VOLUME_DISCOUNT = 3,// 量价折扣
|
|
386
|
-
ORDER_DISCOUNT = 4,// 订单折扣
|
|
387
|
-
PRICE_DISCOUNT = 5
|
|
388
|
-
}
|
|
389
|
-
declare enum BuyRuleType {
|
|
390
|
-
BUY_GET_GIFT = 1,// 买赠
|
|
391
|
-
SPEND_GET_GIFT = 2
|
|
392
|
-
}
|
|
393
|
-
declare enum SpendMoneyType {
|
|
394
|
-
ORIGIN_PRICE = 1,// 原价
|
|
395
|
-
DISCOUNT_PRICE = 2
|
|
396
|
-
}
|
|
397
|
-
interface FunctionGiftResult {
|
|
398
|
-
qualifyingGift: FormattedGift | null;
|
|
399
|
-
nextTierGoal: GiftTier | null;
|
|
400
|
-
activeCampaign: Config | null;
|
|
401
|
-
isLoading: boolean;
|
|
402
|
-
giftProductsResult?: NormalizedProduct[] | [];
|
|
403
|
-
}
|
|
404
|
-
interface FormattedGift {
|
|
405
|
-
tier: GiftTier;
|
|
406
|
-
itemsToAdd: AutoFreeGiftCartLineInput[];
|
|
407
|
-
}
|
|
408
|
-
interface AutoFreeGiftCartLineInput {
|
|
409
|
-
variant: {
|
|
410
|
-
id: string;
|
|
411
|
-
handle: string;
|
|
412
|
-
sku: string;
|
|
413
|
-
};
|
|
414
|
-
quantity: number;
|
|
415
|
-
attributes: {
|
|
416
|
-
key: string;
|
|
417
|
-
value: string;
|
|
418
|
-
}[];
|
|
419
|
-
}
|
|
420
|
-
type AutoFreeGiftItem = {
|
|
421
|
-
line: NormalizedLineItem;
|
|
422
|
-
isSoldOut: boolean;
|
|
423
|
-
};
|
|
424
|
-
type AutoFreeGiftList = AutoFreeGiftItem[] | [];
|
|
425
|
-
|
|
426
532
|
/**
|
|
427
533
|
* [计算型 Hook]
|
|
428
534
|
* 根据购物车、活动配置和用户信息,计算出应得的赠品和下一个目标。
|
|
@@ -532,60 +638,6 @@ interface UseCalcGiftsFromLinesResult {
|
|
|
532
638
|
*/
|
|
533
639
|
declare function useCalcGiftsFromLines({ lines, customer, scriptGiveawayKey, }: UseCalcGiftsFromLinesOptions): UseCalcGiftsFromLinesResult;
|
|
534
640
|
|
|
535
|
-
declare enum OrderDiscountType {
|
|
536
|
-
PERCENTAGE = 1,// 百分比折扣
|
|
537
|
-
FIXED_AMOUNT = 2,// 固定金额折扣
|
|
538
|
-
REDUCE_PRICE = 3
|
|
539
|
-
}
|
|
540
|
-
declare enum OrderBasePriceType {
|
|
541
|
-
ORIGIN_PRICE = 1,// 原价
|
|
542
|
-
MIN_DISCOUNTED_PRICE = 2
|
|
543
|
-
}
|
|
544
|
-
type TieredDiscount = {
|
|
545
|
-
amount: number;
|
|
546
|
-
discount: number;
|
|
547
|
-
discount_type: OrderDiscountType;
|
|
548
|
-
};
|
|
549
|
-
type OrderDiscountConfig = {
|
|
550
|
-
rule_id: number;
|
|
551
|
-
rule_type: number;
|
|
552
|
-
rule_conditions?: RuleCondition[];
|
|
553
|
-
result_detail: {
|
|
554
|
-
main_product: {
|
|
555
|
-
variant_list: Array<{
|
|
556
|
-
variant_id: string;
|
|
557
|
-
sku: string;
|
|
558
|
-
handle: string;
|
|
559
|
-
}>;
|
|
560
|
-
all_store_variant: boolean;
|
|
561
|
-
skip_variants?: Array<{
|
|
562
|
-
variant_id: string;
|
|
563
|
-
sku: string;
|
|
564
|
-
handle: string;
|
|
565
|
-
}>;
|
|
566
|
-
};
|
|
567
|
-
order_discount_conf: {
|
|
568
|
-
base_price: OrderBasePriceType;
|
|
569
|
-
tiered_discounts: TieredDiscount[];
|
|
570
|
-
tiered_discounts_markets?: Record<string, TieredDiscount[]>;
|
|
571
|
-
is_reusable?: boolean;
|
|
572
|
-
min_quantity_items?: number;
|
|
573
|
-
max_apply_times_of_per_order?: number;
|
|
574
|
-
};
|
|
575
|
-
};
|
|
576
|
-
discount_label?: {
|
|
577
|
-
cart_checkout_label?: string;
|
|
578
|
-
product_label?: string;
|
|
579
|
-
sold_out_label?: string;
|
|
580
|
-
};
|
|
581
|
-
frontend_labels?: any[];
|
|
582
|
-
discount_combinations?: {
|
|
583
|
-
other_order_discounts?: boolean;
|
|
584
|
-
other_product_discounts?: boolean;
|
|
585
|
-
shipping_discounts?: boolean;
|
|
586
|
-
};
|
|
587
|
-
};
|
|
588
|
-
|
|
589
641
|
interface OrderDiscountResult {
|
|
590
642
|
qualifyingDiscount: TieredDiscount | null;
|
|
591
643
|
nextTierGoal: TieredDiscount | null;
|
|
@@ -1047,6 +1099,9 @@ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
|
|
|
1047
1099
|
max: number;
|
|
1048
1100
|
};
|
|
1049
1101
|
|
|
1102
|
+
/**
|
|
1103
|
+
* 更新购物车中各个 item 的折后价相关的属性
|
|
1104
|
+
*/
|
|
1050
1105
|
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
1051
1106
|
cart?: NormalizedCart;
|
|
1052
1107
|
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
@@ -1058,26 +1113,6 @@ declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoad
|
|
|
1058
1113
|
};
|
|
1059
1114
|
}) => void;
|
|
1060
1115
|
|
|
1061
|
-
declare enum PriceDiscountType {
|
|
1062
|
-
PERCENTAGE = 1,// 百分比折扣
|
|
1063
|
-
FIXED_AMOUNT = 2
|
|
1064
|
-
}
|
|
1065
|
-
declare enum PriceBasePriceType {
|
|
1066
|
-
MIN_DISCOUNTED_PRICE = 1,// 最低折扣价
|
|
1067
|
-
MIN_TOTAL_PRICE = 2
|
|
1068
|
-
}
|
|
1069
|
-
type PriceDiscountConfig = {
|
|
1070
|
-
rule_id: number;
|
|
1071
|
-
rule_type: number;
|
|
1072
|
-
discount_type: PriceDiscountType;
|
|
1073
|
-
discount_value: number;
|
|
1074
|
-
base_price_type: PriceBasePriceType;
|
|
1075
|
-
applicable_products: Array<{
|
|
1076
|
-
product_id: string;
|
|
1077
|
-
variant_id?: string;
|
|
1078
|
-
}>;
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
1116
|
declare const currencyCodeMapping: Record<string, string>;
|
|
1082
1117
|
declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
|
|
1083
1118
|
throwOnError?: boolean;
|
|
@@ -1896,4 +1931,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1896
1931
|
*/
|
|
1897
1932
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1898
1933
|
|
|
1899
|
-
export { type AddCartLinesInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryData, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberProduct, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateCartAttributesInput, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInCartProps, type UseIntersectionOptions, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions, type UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdatePlusMemberDeliveryOptionsProps, type VariantItem, type VariantMedia, type VideoMedia, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddPlusMemberProductsToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusAnnualProductVariant, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberItemCustomAttributes, usePlusMonthlyProductVariant, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethodAvailableCheck, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
1934
|
+
export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryData, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberProduct, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInCartProps, type UseIntersectionOptions, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions, type UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdatePlusMemberDeliveryOptionsProps, type VariantItem, type VariantMedia, type VideoMedia, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddPlusMemberProductsToCart, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusAnnualProductVariant, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberItemCustomAttributes, usePlusMonthlyProductVariant, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethodAvailableCheck, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
package/dist/hooks/index.js
CHANGED
|
@@ -912,6 +912,61 @@ function useRemoveCartCodes(options) {
|
|
|
912
912
|
return useSWRMutation__default.default("remove-codes", removeCodes, options);
|
|
913
913
|
}
|
|
914
914
|
|
|
915
|
+
// src/hooks/cart/utils/add-to-cart.ts
|
|
916
|
+
var getLinesWithAttributes = ({
|
|
917
|
+
cart,
|
|
918
|
+
lineItems
|
|
919
|
+
}) => {
|
|
920
|
+
return lineItems.map((line) => {
|
|
921
|
+
const sameLineInCart = cart?.lineItems.find(
|
|
922
|
+
(lineInCart) => lineInCart.variant.sku === line.variant?.sku && lineInCart.product?.handle === line.variant?.product?.handle
|
|
923
|
+
);
|
|
924
|
+
const codeAmountAttribute = sameLineInCart?.customAttributes?.find(
|
|
925
|
+
(attr) => attr.key === CODE_AMOUNT_KEY
|
|
926
|
+
);
|
|
927
|
+
const scriptCodeAmountAttribute = sameLineInCart?.customAttributes?.find(
|
|
928
|
+
(attr) => attr.key === SCRIPT_CODE_AMOUNT_KEY
|
|
929
|
+
);
|
|
930
|
+
let functionAttribute = null;
|
|
931
|
+
try {
|
|
932
|
+
functionAttribute = sameLineInCart?.customAttributes?.find(
|
|
933
|
+
(attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY && JSON.parse(attr.value)?.discounted_amount
|
|
934
|
+
);
|
|
935
|
+
} catch (error) {
|
|
936
|
+
}
|
|
937
|
+
if (codeAmountAttribute || functionAttribute || scriptCodeAmountAttribute) {
|
|
938
|
+
return {
|
|
939
|
+
...line,
|
|
940
|
+
attributes: [
|
|
941
|
+
...line.attributes || [],
|
|
942
|
+
codeAmountAttribute,
|
|
943
|
+
functionAttribute,
|
|
944
|
+
scriptCodeAmountAttribute
|
|
945
|
+
].filter(Boolean)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
return line;
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
var getLinesWithFunctionAttributes = (lineItems) => {
|
|
952
|
+
return lineItems.map((line) => {
|
|
953
|
+
let itemAttributes = line.attributes || [];
|
|
954
|
+
const functionEnvAttribute = itemAttributes.find((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
955
|
+
if (!functionEnvAttribute) {
|
|
956
|
+
itemAttributes = itemAttributes.concat([
|
|
957
|
+
{
|
|
958
|
+
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
959
|
+
value: JSON.stringify({
|
|
960
|
+
is_gift: false,
|
|
961
|
+
discounted_amount: Number(line.variant?.finalPrice?.amount || line.variant?.price?.amount) * (line.quantity || 1)
|
|
962
|
+
})
|
|
963
|
+
}
|
|
964
|
+
]);
|
|
965
|
+
}
|
|
966
|
+
return { ...line, attributes: itemAttributes };
|
|
967
|
+
});
|
|
968
|
+
};
|
|
969
|
+
|
|
915
970
|
// src/hooks/cart/use-add-to-cart.ts
|
|
916
971
|
function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
917
972
|
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
@@ -935,7 +990,12 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
935
990
|
if (!lineItems || lineItems.length === 0) {
|
|
936
991
|
return;
|
|
937
992
|
}
|
|
938
|
-
const
|
|
993
|
+
const linesWithAttributes = getLinesWithAttributes({
|
|
994
|
+
cart,
|
|
995
|
+
lineItems
|
|
996
|
+
});
|
|
997
|
+
const linesWithFunctionAttributes = getLinesWithFunctionAttributes(linesWithAttributes);
|
|
998
|
+
const lines = linesWithFunctionAttributes.map((item) => ({
|
|
939
999
|
merchandiseId: item.variant?.id || "",
|
|
940
1000
|
quantity: item.quantity || 1,
|
|
941
1001
|
attributes: item.attributes,
|
|
@@ -1086,7 +1146,8 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
|
1086
1146
|
if (!lineItems || lineItems.length === 0) {
|
|
1087
1147
|
return;
|
|
1088
1148
|
}
|
|
1089
|
-
const
|
|
1149
|
+
const linesWithFunctionAttributes = getLinesWithFunctionAttributes(lineItems);
|
|
1150
|
+
const lines = linesWithFunctionAttributes.map((item) => ({
|
|
1090
1151
|
merchandiseId: item.variant?.id || "",
|
|
1091
1152
|
quantity: item.quantity || 1,
|
|
1092
1153
|
attributes: item.attributes,
|
|
@@ -1539,7 +1600,7 @@ var useUpdateLineCodeAmountAttributes = ({
|
|
|
1539
1600
|
);
|
|
1540
1601
|
const functionEnvValue = getDiscountEnvAttributeValue(line.customAttributes);
|
|
1541
1602
|
const hasSameFunctionEnvAttribute = Number(functionEnvValue.discounted_amount) === Number(line.totalAmount);
|
|
1542
|
-
if (!hasSameFunctionEnvAttribute && hasFunctionEnvAttribute) {
|
|
1603
|
+
if (!hasSameFunctionEnvAttribute && hasFunctionEnvAttribute && !functionEnvValue.is_gift) {
|
|
1543
1604
|
attrNeedUpdate.push({
|
|
1544
1605
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
1545
1606
|
value: JSON.stringify({
|