|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
import Address from "./address" |
|
3
|
import CreditLine from "./credit-line" |
|
4
|
import LineItem from "./line-item" |
|
5
|
import ShippingMethod from "./shipping-method" |
|
6
|
|
|
7
|
/** |
|
8
|
* Represents a shopping cart containing items and associated data. |
|
9
|
*/ |
|
10
|
const Cart = model |
|
11
|
.define("Cart", { |
|
12
|
/** |
|
13
|
* The unique identifier of the cart. |
|
14
|
*/ |
|
15
|
id: model.id({ prefix: "cart" }).primaryKey(), |
|
16
|
/** |
|
17
|
* The ID of the region the cart belongs to. |
|
18
|
*/ |
|
19
|
region_id: model.text().nullable(), |
|
20
|
/** |
|
21
|
* The ID of the customer the cart belongs to. |
|
22
|
*/ |
|
23
|
customer_id: model.text().nullable(), |
|
24
|
/** |
|
25
|
* The ID of the sales channel the cart is associated with. |
|
26
|
*/ |
|
27
|
sales_channel_id: model.text().nullable(), |
|
28
|
/** |
|
29
|
* The email address associated with the cart. |
|
30
|
*/ |
|
31
|
email: model.text().nullable(), |
|
32
|
/** |
|
33
|
* The currency code used for the cart. |
|
34
|
*/ |
|
35
|
currency_code: model.text(), |
|
36
|
/** |
|
37
|
* The BCP 47 language tag code of the locale |
|
38
|
* |
|
39
|
* @since 2.12.3 |
|
40
|
* |
|
41
|
* @example |
|
42
|
* "en-US" |
|
43
|
*/ |
|
44
|
locale: model.text().nullable(), |
|
45
|
/** |
|
46
|
* Additional metadata for the cart. |
|
47
|
*/ |
|
48
|
metadata: model.json().nullable(), |
|
49
|
/** |
|
50
|
* The timestamp when the cart was completed/converted to an order. |
|
51
|
*/ |
|
52
|
completed_at: model.dateTime().nullable(), |
|
53
|
/** |
|
54
|
* The shipping address for the cart. |
|
55
|
*/ |
|
56
|
shipping_address: model |
|
57
|
.hasOne(() => Address, { |
|
58
|
mappedBy: undefined, |
|
59
|
foreignKey: true, |
|
60
|
}) |
|
61
|
.nullable(), |
|
62
|
/** |
|
63
|
* The billing address for the cart. |
|
64
|
*/ |
|
65
|
billing_address: model |
|
66
|
.hasOne(() => Address, { |
|
67
|
mappedBy: undefined, |
|
68
|
foreignKey: true, |
|
69
|
}) |
|
70
|
.nullable(), |
|
71
|
/** |
|
72
|
* The line items in the cart. |
|
73
|
*/ |
|
74
|
items: model.hasMany(() => LineItem, { |
|
75
|
mappedBy: "cart", |
|
76
|
}), |
|
77
|
/** |
|
78
|
* The credit lines associated with the cart. |
|
79
|
*/ |
|
80
|
credit_lines: model.hasMany(() => CreditLine, { |
|
81
|
mappedBy: "cart", |
|
82
|
}), |
|
83
|
/** |
|
84
|
* The shipping methods selected for the cart. |
|
85
|
*/ |
|
86
|
shipping_methods: model.hasMany(() => ShippingMethod, { |
|
87
|
mappedBy: "cart", |
|
88
|
}), |
|
89
|
/** |
|
90
|
* The original total amount of all items in the cart before any discounts. |
|
91
|
* |
|
92
|
* @since 2.13.7 |
|
93
|
*/ |
|
94
|
original_item_total: model.bigNumber().computed(), |
|
95
|
/** |
|
96
|
* The original subtotal amount of all items in the cart before any discounts. |
|
97
|
* |
|
98
|
* @since 2.13.7 |
|
99
|
*/ |
|
100
|
original_item_subtotal: model.bigNumber().computed(), |
|
101
|
/** |
|
102
|
* The original tax total amount of all items in the cart before any discounts. |
|
103
|
* |
|
104
|
* @since 2.13.7 |
|
105
|
*/ |
|
106
|
original_item_tax_total: model.bigNumber().computed(), |
|
107
|
/** |
|
108
|
* The total amount of all items in the cart after discounts. |
|
109
|
* |
|
110
|
* @since 2.13.7 |
|
111
|
*/ |
|
112
|
item_total: model.bigNumber().computed(), |
|
113
|
/** |
|
114
|
* The subtotal amount of all items in the cart after discounts. |
|
115
|
* |
|
116
|
* @since 2.13.7 |
|
117
|
*/ |
|
118
|
item_subtotal: model.bigNumber().computed(), |
|
119
|
/** |
|
120
|
* The tax total amount of all items in the cart after discounts. |
|
121
|
* |
|
122
|
* @since 2.13.7 |
|
123
|
*/ |
|
124
|
item_tax_total: model.bigNumber().computed(), |
|
125
|
/** |
|
126
|
* The original total amount of the cart before any discounts. |
|
127
|
* |
|
128
|
* @since 2.13.7 |
|
129
|
*/ |
|
130
|
original_total: model.bigNumber().computed(), |
|
131
|
/** |
|
132
|
* The original subtotal amount of the cart before any discounts. |
|
133
|
* |
|
134
|
* @since 2.13.7 |
|
135
|
*/ |
|
136
|
original_subtotal: model.bigNumber().computed(), |
|
137
|
/** |
|
138
|
* The original tax total amount of the cart before any discounts. |
|
139
|
* |
|
140
|
* @since 2.13.7 |
|
141
|
*/ |
|
142
|
original_tax_total: model.bigNumber().computed(), |
|
143
|
/** |
|
144
|
* The total amount of the cart after discounts. |
|
145
|
*/ |
|
146
|
total: model.bigNumber().computed(), |
|
147
|
/** |
|
148
|
* The subtotal amount of the cart after discounts. |
|
149
|
*/ |
|
150
|
subtotal: model.bigNumber().computed(), |
|
151
|
/** |
|
152
|
* The tax total amount of the cart. |
|
153
|
*/ |
|
154
|
tax_total: model.bigNumber().computed(), |
|
155
|
/** |
|
156
|
* The total discount amount applied to the cart. |
|
157
|
*/ |
|
158
|
discount_total: model.bigNumber().computed(), |
|
159
|
/** |
|
160
|
* The total tax amount on discounts applied to the cart. |
|
161
|
*/ |
|
162
|
discount_tax_total: model.bigNumber().computed(), |
|
163
|
/** |
|
164
|
* The total gift card amount applied to the cart. |
|
165
|
*/ |
|
166
|
gift_card_total: model.bigNumber().computed(), |
|
167
|
/** |
|
168
|
* The total tax amount on gift cards applied to the cart. |
|
169
|
*/ |
|
170
|
gift_card_tax_total: model.bigNumber().computed(), |
|
171
|
/** |
|
172
|
* The total shipping amount for the cart. |
|
173
|
*/ |
|
174
|
shipping_total: model.bigNumber().computed(), |
|
175
|
/** |
|
176
|
* The shipping subtotal amount for the cart. |
|
177
|
*/ |
|
178
|
shipping_subtotal: model.bigNumber().computed(), |
|
179
|
/** |
|
180
|
* The total tax amount on shipping for the cart. |
|
181
|
*/ |
|
182
|
shipping_tax_total: model.bigNumber().computed(), |
|
183
|
/** |
|
184
|
* The original total shipping amount for the cart before discounts. |
|
185
|
*/ |
|
186
|
original_shipping_total: model.bigNumber().computed(), |
|
187
|
/** |
|
188
|
* The original shipping subtotal amount for the cart before discounts. |
|
189
|
*/ |
|
190
|
original_shipping_subtotal: model.bigNumber().computed(), |
|
191
|
/** |
|
192
|
* The original total tax amount on shipping for the cart before discounts. |
|
193
|
*/ |
|
194
|
original_shipping_tax_total: model.bigNumber().computed(), |
|
195
|
}) |
|
196
|
.cascades({ |
|
197
|
delete: [ |
|
198
|
"items", |
|
199
|
"shipping_methods", |
|
200
|
"shipping_address", |
|
201
|
"billing_address", |
|
202
|
], |
|
203
|
}) |
|
204
|
.indexes([ |
|
205
|
{ |
|
206
|
name: "IDX_cart_region_id", |
|
207
|
on: ["region_id"], |
|
208
|
where: "deleted_at IS NULL AND region_id IS NOT NULL", |
|
209
|
}, |
|
210
|
{ |
|
211
|
name: "IDX_cart_customer_id", |
|
212
|
on: ["customer_id"], |
|
213
|
where: "deleted_at IS NULL AND customer_id IS NOT NULL", |
|
214
|
}, |
|
215
|
{ |
|
216
|
name: "IDX_cart_sales_channel_id", |
|
217
|
on: ["sales_channel_id"], |
|
218
|
where: "deleted_at IS NULL AND sales_channel_id IS NOT NULL", |
|
219
|
}, |
|
220
|
{ |
|
221
|
name: "IDX_cart_curency_code", |
|
222
|
on: ["currency_code"], |
|
223
|
where: "deleted_at IS NULL", |
|
224
|
}, |
|
225
|
{ |
|
226
|
name: "IDX_cart_shipping_address_id", |
|
227
|
on: ["shipping_address_id"], |
|
228
|
where: "deleted_at IS NULL AND shipping_address_id IS NOT NULL", |
|
229
|
}, |
|
230
|
{ |
|
231
|
name: "IDX_cart_billing_address_id", |
|
232
|
on: ["billing_address_id"], |
|
233
|
where: "deleted_at IS NULL AND billing_address_id IS NOT NULL", |
|
234
|
}, |
|
235
|
]) |
|
236
|
|
|
237
|
export default Cart |