-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart-discount.ts
753 lines (751 loc) · 20 KB
/
cart-discount.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
/**
* Code generated by [commercetools RMF-Codegen](https://github.com/commercetools/rmf-codegen). DO NOT EDIT.
* Please don't change this file manually but run `rmf-codegen generate raml_file_path -o output_path -t typescript_client` to update it.
* For more information about the commercetools platform APIs, visit https://docs.commercetools.com/.
*/
import { ChannelReference, ChannelResourceIdentifier } from './channel.js'
import {
BaseResource,
CentPrecisionMoney,
CreatedBy,
LastModifiedBy,
LocalizedString,
Money,
Reference,
} from './common.js'
import { ProductReference, ProductResourceIdentifier } from './product.js'
import { CustomFields, CustomFieldsDraft, FieldContainer, TypeResourceIdentifier } from './type.js'
export interface CartDiscount extends BaseResource {
/**
* Unique identifier of the CartDiscount.
*
*/
readonly id: string
/**
* Current version of the CartDiscount.
*
*
*/
readonly version: number
/**
* Date and time (UTC) for the CartDiscount was initially created.
*
*
*/
readonly createdAt: string
/**
* Date and time (UTC) for the CartDiscount was last updated.
*
*
*/
readonly lastModifiedAt: string
/**
* Present on resources updated after 1 February 2019 except for [events not tracked](/../api/client-logging#events-tracked).
*
*
*/
readonly lastModifiedBy?: LastModifiedBy
/**
* Present on resources created after 1 February 2019 except for [events not tracked](/../api/client-logging#events-tracked).
*
*
*/
readonly createdBy?: CreatedBy
/**
* Name of the CartDiscount.
*
*
*/
readonly name: LocalizedString
/**
* User-defined unique identifier of the CartDiscount.
*
*
*/
readonly key?: string
/**
* Description of the CartDiscount.
*
*
*/
readonly description?: LocalizedString
/**
* Effect of the CartDiscount.
*
*
*/
readonly value: CartDiscountValue
/**
* Valid [Cart Predicate](/../api/projects/predicates#cart-predicates).
*
*
*/
readonly cartPredicate: string
/**
* Sets a [CartDiscountTarget](ctp:api:type:CartDiscountTarget). Empty if `value` has type `giftLineItem`.
*
*
*/
readonly target?: CartDiscountTarget
/**
* Value between `0` and `1`.
* All matching CartDiscounts are applied to a Cart in the order defined by this field.
* A Discount with a higher sortOrder is prioritized.
* The sort order is unambiguous among all CartDiscounts.
*
*
*/
readonly sortOrder: string
/**
* Indicates if the CartDiscount is active and can be applied to the Cart.
*
*
*/
readonly isActive: boolean
/**
* Date and time (UTC) from which the Discount is effective.
*
*
*/
readonly validFrom?: string
/**
* Date and time (UTC) until which the Discount is effective.
*
*
*/
readonly validUntil?: string
/**
* Indicates if the Discount can be used in connection with a [DiscountCode](ctp:api:type:DiscountCode).
*
*
*/
readonly requiresDiscountCode: boolean
/**
* References of all resources that are addressed in the predicate.
* The API generates this array from the predicate.
*
*
*/
readonly references: Reference[]
/**
* Indicates whether the application of the CartDiscount causes other discounts to be ignored.
*
*
*/
readonly stackingMode: StackingMode
/**
* Custom Fields of the CartDiscount.
*
*
*/
readonly custom?: CustomFields
}
export interface CartDiscountDraft {
/**
* Name of the CartDiscount.
*
*
*/
readonly name: LocalizedString
/**
* User-defined unique identifier for the CartDiscount.
*
*
*/
readonly key?: string
/**
* Description of the CartDiscount.
*
*
*/
readonly description?: LocalizedString
/**
* Effect of the CartDiscount.
* For a [target](ctp:api:type:CartDiscountTarget), relative or absolute Discount values or a fixed item Price value can be specified. If no target is specified, a [Gift Line Item](/../api/projects/cartDiscounts#gift-line-item) can be added to the Cart.
*
*
*/
readonly value: CartDiscountValueDraft
/**
* Valid [Cart Predicate](/../api/projects/predicates#cart-predicates).
*
*
*/
readonly cartPredicate: string
/**
* Must not be set when the `value` has type `giftLineItem`, otherwise a [CartDiscountTarget](ctp:api:type:CartDiscountTarget) must be set.
*
*
*/
readonly target?: CartDiscountTarget
/**
* Value between `0` and `1`.
* A Discount with a higher sortOrder is prioritized.
* The sort order must be unambiguous among all CartDiscounts.
*
*
*/
readonly sortOrder: string
/**
* Only active Discounts can be applied to the Cart.
*
*
*/
readonly isActive?: boolean
/**
* Date and time (UTC) from which the Discount is effective.
*
*
*/
readonly validFrom?: string
/**
* Date and time (UTC) until which the Discount is effective.
*
*
*/
readonly validUntil?: string
/**
* States whether the Discount can only be used in a connection with a [DiscountCode](ctp:api:type:DiscountCode).
*
*
*/
readonly requiresDiscountCode?: boolean
/**
* Specifies whether the application of this discount causes the following discounts to be ignored.
*
*
*/
readonly stackingMode?: StackingMode
/**
* Custom Fields of the CartDiscount.
*
*
*/
readonly custom?: CustomFieldsDraft
}
/**
* [PagedQueryResult](/../api/general-concepts#pagedqueryresult) with `results` containing an array of [CartDiscount](ctp:api:type:CartDiscount).
*
*/
export interface CartDiscountPagedQueryResponse {
/**
* Number of [results requested](/../api/general-concepts#limit).
*
*
*/
readonly limit: number
/**
* Number of [elements skipped](/../api/general-concepts#offset).
*
*
*/
readonly offset: number
/**
* Actual number of results returned.
*
*
*/
readonly count: number
/**
* Total number of results matching the query.
* This number is an estimation that is not [strongly consistent](/../api/general-concepts#strong-consistency).
* This field is returned by default.
* For improved performance, calculating this field can be deactivated by using the query parameter `withTotal=false`.
* When the results are filtered with a [Query Predicate](/../api/predicates/query), `total` is subject to a [limit](/../api/limits#queries).
*
*
*/
readonly total?: number
/**
* [CartDiscounts](ctp:api:type:CartDiscount) matching the query.
*
*
*/
readonly results: CartDiscount[]
}
/**
* [Reference](ctp:api:type:Reference) to a [CartDiscount](ctp:api:type:CartDiscount).
*
*/
export interface CartDiscountReference {
readonly typeId: 'cart-discount'
/**
* Unique identifier of the referenced [CartDiscount](ctp:api:type:CartDiscount).
*
*
*/
readonly id: string
/**
* Contains the representation of the expanded CartDiscount. Only present in responses to requests with [Reference Expansion](/../api/general-concepts#reference-expansion) for CartDiscounts.
*
*
*/
readonly obj?: CartDiscount
}
/**
* [ResourceIdentifier](ctp:api:type:ResourceIdentifier) to a [CartDiscount](ctp:api:type:CartDiscount).
*
*/
export interface CartDiscountResourceIdentifier {
readonly typeId: 'cart-discount'
/**
* Unique identifier of the referenced [CartDiscount](ctp:api:type:CartDiscount). Either `id` or `key` is required.
*
*
*/
readonly id?: string
/**
* User-defined unique identifier of the referenced [CartDiscount](ctp:api:type:CartDiscount). Either `id` or `key` is required.
*
*
*/
readonly key?: string
}
export type CartDiscountTarget =
| CartDiscountCustomLineItemsTarget
| CartDiscountLineItemsTarget
| CartDiscountShippingCostTarget
| MultiBuyCustomLineItemsTarget
| MultiBuyLineItemsTarget
/**
* Discount is applied to [CustomLineItems](ctp:api:type:CustomLineItem) matching the `predicate`.
*
*/
export interface CartDiscountCustomLineItemsTarget {
readonly type: 'customLineItems'
/**
* Valid [CustomLineItem target predicate](/../api/projects/predicates#customlineitem-field-identifiers).
*
*
*/
readonly predicate: string
}
/**
* Discount is applied to [LineItems](ctp:api:type:LineItem) matching the `predicate`.
*
*/
export interface CartDiscountLineItemsTarget {
readonly type: 'lineItems'
/**
* Valid [LineItem target predicate](/../api/projects/predicates#lineitem-field-identifiers).
*
*
*/
readonly predicate: string
}
/**
* Discount is applied to the shipping costs of the [Cart](ctp:api:type:Cart).
*
*/
export interface CartDiscountShippingCostTarget {
readonly type: 'shipping'
}
export interface CartDiscountUpdate {
/**
* Expected version of the CartDiscount on which the changes should be applied. If the expected version does not match the actual version, a [ConcurrentModification](ctp:api:type:ConcurrentModificationError) error is returned.
*
*
*/
readonly version: number
/**
* Update actions to be performed on the CartDiscount.
*
*
*/
readonly actions: CartDiscountUpdateAction[]
}
export type CartDiscountUpdateAction =
| CartDiscountChangeCartPredicateAction
| CartDiscountChangeIsActiveAction
| CartDiscountChangeNameAction
| CartDiscountChangeRequiresDiscountCodeAction
| CartDiscountChangeSortOrderAction
| CartDiscountChangeStackingModeAction
| CartDiscountChangeTargetAction
| CartDiscountChangeValueAction
| CartDiscountSetCustomFieldAction
| CartDiscountSetCustomTypeAction
| CartDiscountSetDescriptionAction
| CartDiscountSetKeyAction
| CartDiscountSetValidFromAction
| CartDiscountSetValidFromAndUntilAction
| CartDiscountSetValidUntilAction
export type CartDiscountValue =
| CartDiscountValueAbsolute
| CartDiscountValueFixed
| CartDiscountValueGiftLineItem
| CartDiscountValueRelative
/**
* Discounts the [CartDiscountTarget](ctp:api:type:CartDiscountTarget) by an absolute amount (not allowed for [MultiBuyLineItemsTarget](ctp:api:type:MultiBuyLineItemsTarget) and [MultiBuyCustomLineItemsTarget](ctp:api:type:MultiBuyCustomLineItemsTarget)).
*
*/
export interface CartDiscountValueAbsolute {
readonly type: 'absolute'
/**
* Cent precision money values in different currencies.
*
*
*/
readonly money: CentPrecisionMoney[]
}
export type CartDiscountValueDraft =
| CartDiscountValueAbsoluteDraft
| CartDiscountValueFixedDraft
| CartDiscountValueGiftLineItemDraft
| CartDiscountValueRelativeDraft
export interface CartDiscountValueAbsoluteDraft {
readonly type: 'absolute'
/**
* Money values in different currencies.
* An absolute Cart Discount will only match a price if this array contains a value with the same currency. If it contains 10€ and 15$, the matching € price will be decreased by 10€ and the matching $ price will be decreased by 15$.
*
*
*/
readonly money: Money[]
}
/**
* Sets the [DiscountedLineItemPrice](ctp:api:type:DiscountedLineItemPrice) of the [CartDiscountLineItemsTarget](ctp:api:type:CartDiscountLineItemsTarget) or [CartDiscountCustomLineItemsTarget](ctp:api:type:CartDiscountCustomLineItemsTarget) to the value specified in the `money` field, if it is lower than the current Line Item price for the same currency. If the Line Item price is already discounted to a price equal to or lower than the respective price in the `money` field, this Discount is not applied.
*
*/
export interface CartDiscountValueFixed {
readonly type: 'fixed'
/**
* Cent precision money values in different currencies.
*
*
*/
readonly money: CentPrecisionMoney[]
}
/**
* Sets the [DiscountedLineItemPrice](ctp:api:type:DiscountedLineItemPrice) of the [CartDiscountLineItemsTarget](ctp:api:type:CartDiscountLineItemsTarget) or [CartDiscountCustomLineItemsTarget](ctp:api:type:CartDiscountCustomLineItemsTarget) to the value specified in the `money` field, if it is lower than the current Line Item price for the same currency. If the Line Item price is already discounted to a price equal to or lower than the respective price in the `money` field, this Discount is not applied.
*
*/
export interface CartDiscountValueFixedDraft {
readonly type: 'fixed'
/**
* Money values in different currencies.
* A fixed Cart Discount will only match a price if this array contains a value with the same currency. If it contains 10€ and 15$, the matching € price will be discounted by 10€ and the matching $ price will be discounted to 15$.
*
*
*/
readonly money: Money[]
}
export interface CartDiscountValueGiftLineItem {
readonly type: 'giftLineItem'
/**
* Reference to a Product.
*
*
*/
readonly product: ProductReference
/**
* [ProductVariant](ctp:api:type:ProductVariant) of the Product.
*
*
*/
readonly variantId: number
/**
* Channel must have the [ChannelRoleEnum](ctp:api:type:ChannelRoleEnum) `InventorySupply`.
*
*
*/
readonly supplyChannel?: ChannelReference
/**
* Channel must have the [ChannelRoleEnum](ctp:api:type:ChannelRoleEnum) `ProductDistribution`.
*
*
*/
readonly distributionChannel?: ChannelReference
}
export interface CartDiscountValueGiftLineItemDraft {
readonly type: 'giftLineItem'
/**
* ResourceIdentifier of a Product.
*
*
*/
readonly product: ProductResourceIdentifier
/**
* [ProductVariant](ctp:api:type:ProductVariant) of the Product.
*
*
*/
readonly variantId: number
/**
* Channel must have the role `InventorySupply`.
*
*
*/
readonly supplyChannel?: ChannelResourceIdentifier
/**
* Channel must have the role `ProductDistribution`.
*
*
*/
readonly distributionChannel?: ChannelResourceIdentifier
}
/**
* Discounts the [CartDiscountTarget](ctp:api:type:CartDiscountTarget) relative to its price.
*
*/
export interface CartDiscountValueRelative {
readonly type: 'relative'
/**
* Fraction (per ten thousand) the price is reduced by. For example, `1000` will result in a 10% price reduction.
*
*
*/
readonly permyriad: number
}
export interface CartDiscountValueRelativeDraft {
readonly type: 'relative'
/**
* Fraction (per ten thousand) the price is reduced by. For example, `1000` will result in a 10% price reduction.
*
*
*/
readonly permyriad: number
}
/**
* This Discount target is similar to `MultiBuyLineItems`, but is applied on Custom Line Items instead of Line Items.
*
*/
export interface MultiBuyCustomLineItemsTarget {
readonly type: 'multiBuyCustomLineItems'
/**
* Valid [CustomLineItems target predicate](/../api/projects/predicates#customlineitem-field-identifiers). The Discount will be applied to Custom Line Items that are matched by the predicate.
*
*
*/
readonly predicate: string
/**
* Number of Custom Line Items to be present in order to trigger an application of this Discount.
*
*
*/
readonly triggerQuantity: number
/**
* Number of Custom Line Items that are discounted per application of this Discount.
*
*
*/
readonly discountedQuantity: number
/**
* Maximum number of times this Discount can be applied.
*
*
*/
readonly maxOccurrence?: number
/**
* Discounts particular Line Items only according to the SelectionMode.
*
*
*/
readonly selectionMode: SelectionMode
}
export interface MultiBuyLineItemsTarget {
readonly type: 'multiBuyLineItems'
/**
* Valid [LineItem target predicate](/../api/projects/predicates#lineitem-field-identifiers). The Discount will be applied to Line Items that are matched by the predicate.
*
*
*/
readonly predicate: string
/**
* Number of Line Items to be present in order to trigger an application of this Discount.
*
*
*/
readonly triggerQuantity: number
/**
* Number of Line Items that are discounted per application of this Discount.
*
*
*/
readonly discountedQuantity: number
/**
* Maximum number of times this Discount can be applied.
*
*
*/
readonly maxOccurrence?: number
/**
* Discounts particular Line Items only according to the SelectionMode.
*
*
*/
readonly selectionMode: SelectionMode
}
/**
* Defines which matching items are to be discounted.
*
*/
export type SelectionMode = 'Cheapest' | 'MostExpensive' | string
/**
* Describes how the Cart Discount interacts with other Discounts.
*
*/
export type StackingMode = 'Stacking' | 'StopAfterThisDiscount' | string
export interface CartDiscountChangeCartPredicateAction {
readonly action: 'changeCartPredicate'
/**
* New value to set.
*
*
*/
readonly cartPredicate: string
}
export interface CartDiscountChangeIsActiveAction {
readonly action: 'changeIsActive'
/**
* New value to set.
* If set to `true`, the Discount will be applied to the Cart.
*
*
*/
readonly isActive: boolean
}
export interface CartDiscountChangeNameAction {
readonly action: 'changeName'
/**
* New value to set.
*
*
*/
readonly name: LocalizedString
}
export interface CartDiscountChangeRequiresDiscountCodeAction {
readonly action: 'changeRequiresDiscountCode'
/**
* New value to set.
* If set to `true`, the Discount can only be used in connection with a [DiscountCode](ctp:api:type:DiscountCode).
*
*
*/
readonly requiresDiscountCode: boolean
}
export interface CartDiscountChangeSortOrderAction {
readonly action: 'changeSortOrder'
/**
* New value to set (between `0` and `1`).
* A Discount with a higher sortOrder is prioritized.
*
*
*/
readonly sortOrder: string
}
export interface CartDiscountChangeStackingModeAction {
readonly action: 'changeStackingMode'
/**
* New value to set.
*
*
*/
readonly stackingMode: StackingMode
}
export interface CartDiscountChangeTargetAction {
readonly action: 'changeTarget'
/**
* New value to set.
*
*
*/
readonly target: CartDiscountTarget
}
export interface CartDiscountChangeValueAction {
readonly action: 'changeValue'
/**
* New value to set.
*
*
*/
readonly value: CartDiscountValueDraft
}
export interface CartDiscountSetCustomFieldAction {
readonly action: 'setCustomField'
/**
* Name of the [Custom Field](/../api/projects/custom-fields).
*
*
*/
readonly name: string
/**
* If `value` is absent or `null`, this field will be removed if it exists.
* Removing a field that does not exist returns an [InvalidOperation](ctp:api:type:InvalidOperationError) error.
* If `value` is provided, it is set for the field defined by `name`.
*
*
*/
readonly value?: any
}
export interface CartDiscountSetCustomTypeAction {
readonly action: 'setCustomType'
/**
* Defines the [Type](ctp:api:type:Type) that extends the CartDiscount with [Custom Fields](/../api/projects/custom-fields).
* If absent, any existing Type and Custom Fields are removed from the CartDiscount.
*
*
*/
readonly type?: TypeResourceIdentifier
/**
* Sets the [Custom Fields](/../api/projects/custom-fields) fields for the CartDiscount.
*
*
*/
readonly fields?: FieldContainer
}
export interface CartDiscountSetDescriptionAction {
readonly action: 'setDescription'
/**
* Value to set. If empty, any existing value will be removed.
*
*
*/
readonly description?: LocalizedString
}
export interface CartDiscountSetKeyAction {
readonly action: 'setKey'
/**
* Value to set. If empty, any existing value will be removed.
*
*
*/
readonly key?: string
}
export interface CartDiscountSetValidFromAction {
readonly action: 'setValidFrom'
/**
* Value to set.
* If empty, any existing value will be removed.
*
*
*/
readonly validFrom?: string
}
export interface CartDiscountSetValidFromAndUntilAction {
readonly action: 'setValidFromAndUntil'
/**
* Value to set.
* If empty, any existing value will be removed.
*
*
*/
readonly validFrom?: string
/**
* Value to set.
* If empty, any existing value will be removed.
*
*
*/
readonly validUntil?: string
}
export interface CartDiscountSetValidUntilAction {
readonly action: 'setValidUntil'
/**
* Value to set.
* If empty, any existing value will be removed.
*
*
*/
readonly validUntil?: string
}