|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
import Cart from "./cart" |
|
3
|
import LineItemAdjustment from "./line-item-adjustment" |
|
4
|
import LineItemTaxLine from "./line-item-tax-line" |
|
5
|
|
|
6
|
const LineItem = model |
|
7
|
.define( |
|
8
|
{ name: "LineItem", tableName: "cart_line_item" }, |
|
9
|
{ |
|
10
|
id: model.id({ prefix: "cali" }).primaryKey(), |
|
11
|
title: model.text(), |
|
12
|
subtitle: model.text().nullable(), |
|
13
|
thumbnail: model.text().nullable(), |
|
14
|
quantity: model.number(), |
|
15
|
variant_id: model.text().nullable(), |
|
16
|
product_id: model.text().nullable(), |
|
17
|
product_title: model.text().nullable(), |
|
18
|
product_description: model.text().nullable(), |
|
19
|
product_subtitle: model.text().nullable(), |
|
20
|
product_type: model.text().nullable(), |
|
21
|
product_type_id: model.text().nullable(), |
|
22
|
product_collection: model.text().nullable(), |
|
23
|
product_handle: model.text().nullable(), |
|
24
|
variant_sku: model.text().nullable(), |
|
25
|
variant_barcode: model.text().nullable(), |
|
26
|
variant_title: model.text().nullable(), |
|
27
|
variant_option_values: model.json().nullable(), |
|
28
|
requires_shipping: model.boolean().default(true), |
|
29
|
is_discountable: model.boolean().default(true), |
|
30
|
is_giftcard: model.boolean().default(false), |
|
31
|
is_tax_inclusive: model.boolean().default(false), |
|
32
|
is_custom_price: model.boolean().default(false), |
|
33
|
compare_at_unit_price: model.bigNumber().nullable(), |
|
34
|
unit_price: model.bigNumber(), |
|
35
|
metadata: model.json().nullable(), |
|
36
|
original_total: model.bigNumber().computed(), |
|
37
|
original_subtotal: model.bigNumber().computed(), |
|
38
|
original_tax_total: model.bigNumber().computed(), |
|
39
|
item_total: model.bigNumber().computed(), |
|
40
|
item_subtotal: model.bigNumber().computed(), |
|
41
|
item_tax_total: model.bigNumber().computed(), |
|
42
|
total: model.bigNumber().computed(), |
|
43
|
subtotal: model.bigNumber().computed(), |
|
44
|
tax_total: model.bigNumber().computed(), |
|
45
|
discount_total: model.bigNumber().computed(), |
|
46
|
discount_tax_total: model.bigNumber().computed(), |
|
47
|
adjustments: model.hasMany(() => LineItemAdjustment, { |
|
48
|
mappedBy: "item", |
|
49
|
}), |
|
50
|
tax_lines: model.hasMany(() => LineItemTaxLine, { |
|
51
|
mappedBy: "item", |
|
52
|
}), |
|
53
|
cart: model.belongsTo(() => Cart, { |
|
54
|
mappedBy: "items", |
|
55
|
}), |
|
56
|
} |
|
57
|
) |
|
58
|
.indexes([ |
|
59
|
{ |
|
60
|
name: "IDX_cart_line_item_cart_id", |
|
61
|
on: ["cart_id"], |
|
62
|
where: "deleted_at IS NULL", |
|
63
|
}, |
|
64
|
{ |
|
65
|
name: "IDX_line_item_variant_id", |
|
66
|
on: ["variant_id"], |
|
67
|
where: "deleted_at IS NULL AND variant_id IS NOT NULL", |
|
68
|
}, |
|
69
|
{ |
|
70
|
name: "IDX_line_item_product_id", |
|
71
|
on: ["product_id"], |
|
72
|
where: "deleted_at IS NULL AND product_id IS NOT NULL", |
|
73
|
}, |
|
74
|
{ |
|
75
|
name: "IDX_line_item_product_type_id", |
|
76
|
on: ["product_type_id"], |
|
77
|
where: "deleted_at IS NULL AND product_type_id IS NOT NULL", |
|
78
|
}, |
|
79
|
]) |
|
80
|
.cascades({ |
|
81
|
delete: ["adjustments", "tax_lines"], |
|
82
|
}) |
|
83
|
|
|
84
|
export default LineItem |