feat(cart): Line item adjustments (#6112)

This commit is contained in:
Oli Juhl
2024-01-22 09:55:47 +01:00
committed by GitHub
parent af7af73745
commit 06b33a9b45
21 changed files with 974 additions and 71 deletions
+6 -6
View File
@@ -14,19 +14,19 @@ export default abstract class AdjustmentLine {
id: string
@Property({ columnType: "text", nullable: true })
description?: string | null
description: string | null = null
@Property({ columnType: "text", nullable: true })
promotion_id?: string | null
promotion_id: string | null = null
@Property({ columnType: "text" })
code: string
@Property({ columnType: "text", nullable: true })
code: string | null = null
@Property({ columnType: "numeric" })
@Property({ columnType: "numeric", serializer: Number })
amount: number
@Property({ columnType: "text", nullable: true })
provider_id?: string | null
provider_id: string | null = null
@Property({
onCreate: () => new Date(),
+1 -1
View File
@@ -1,7 +1,7 @@
export { default as Address } from "./address"
export { default as Cart } from "./cart"
export { default as LineItem } from "./line-item"
export { default as LineItemAdjustmentLine } from "./line-item-adjustment-line"
export { default as LineItemAdjustment } from "./line-item-adjustment"
export { default as LineItemTaxLine } from "./line-item-tax-line"
export { default as ShippingMethod } from "./shipping-method"
export { default as ShippingMethodAdjustmentLine } from "./shipping-method-adjustment-line"
@@ -1,20 +1,29 @@
import { generateEntityId } from "@medusajs/utils"
import {
BeforeCreate,
Check,
Entity,
ManyToOne,
OnInit
OnInit,
Property,
} from "@mikro-orm/core"
import AdjustmentLine from "./adjustment-line"
import LineItem from "./line-item"
@Entity({ tableName: "cart_line_item_adjustment_line" })
export default class LineItemAdjustmentLine extends AdjustmentLine {
@Check<LineItemAdjustment>({
expression: (columns) => `${columns.amount} >= 0`,
})
export default class LineItemAdjustment extends AdjustmentLine {
@ManyToOne(() => LineItem, {
joinColumn: "line_item",
fieldName: "line_item_id",
onDelete: "cascade",
nullable: true,
index: "IDX_adjustment_line_item_id",
})
line_item: LineItem
item?: LineItem | null
@Property({ columnType: "text" })
item_id: string
@BeforeCreate()
onCreate() {
+4 -4
View File
@@ -14,7 +14,7 @@ import {
Property,
} from "@mikro-orm/core"
import Cart from "./cart"
import LineItemAdjustmentLine from "./line-item-adjustment-line"
import LineItemAdjustment from "./line-item-adjustment"
import LineItemTaxLine from "./line-item-tax-line"
type OptionalLineItemProps =
@@ -116,13 +116,13 @@ export default class LineItem {
tax_lines = new Collection<LineItemTaxLine>(this)
@OneToMany(
() => LineItemAdjustmentLine,
(adjustment) => adjustment.line_item,
() => LineItemAdjustment,
(adjustment) => adjustment.item,
{
cascade: [Cascade.REMOVE],
}
)
adjustments = new Collection<LineItemAdjustmentLine>(this)
adjustments = new Collection<LineItemAdjustment>(this)
/** COMPUTED PROPERTIES - START */