feat(cart): Shipping method adjustments (#6119)
This commit is contained in:
@@ -4,6 +4,6 @@ export { default as LineItem } from "./line-item"
|
||||
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"
|
||||
export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment"
|
||||
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import AdjustmentLine from "./adjustment-line"
|
||||
import LineItem from "./line-item"
|
||||
|
||||
@Entity({ tableName: "cart_line_item_adjustment_line" })
|
||||
@Entity({ tableName: "cart_line_item_adjustment" })
|
||||
@Check<LineItemAdjustment>({
|
||||
expression: (columns) => `${columns.amount} >= 0`,
|
||||
})
|
||||
@@ -18,7 +18,7 @@ export default class LineItemAdjustment extends AdjustmentLine {
|
||||
@ManyToOne(() => LineItem, {
|
||||
onDelete: "cascade",
|
||||
nullable: true,
|
||||
index: "IDX_adjustment_line_item_id",
|
||||
index: "IDX_adjustment_item_id",
|
||||
})
|
||||
item?: LineItem | null
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import { BeforeCreate, Entity, ManyToOne, OnInit } from "@mikro-orm/core"
|
||||
import AdjustmentLine from "./adjustment-line"
|
||||
import ShippingMethod from "./shipping-method"
|
||||
|
||||
@Entity({ tableName: "cart_shipping_method_adjustment_line" })
|
||||
export default class ShippingMethodAdjustmentLine extends AdjustmentLine {
|
||||
@ManyToOne(() => ShippingMethod, {
|
||||
joinColumn: "shipping_method",
|
||||
fieldName: "shipping_method_id",
|
||||
})
|
||||
shipping_method: ShippingMethod
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "casmadj")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "casmadj")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import AdjustmentLine from "./adjustment-line"
|
||||
import ShippingMethod from "./shipping-method"
|
||||
|
||||
@Entity({ tableName: "cart_shipping_method_adjustment" })
|
||||
export default class ShippingMethodAdjustment extends AdjustmentLine {
|
||||
@ManyToOne(() => ShippingMethod, {
|
||||
onDelete: "cascade",
|
||||
nullable: true,
|
||||
index: "IDX_adjustment_shipping_method_id",
|
||||
})
|
||||
shipping_method: ShippingMethod | null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
shipping_method_id: string
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "casmadj")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "casmadj")
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Cart from "./cart"
|
||||
import ShippingMethodAdjustmentLine from "./shipping-method-adjustment-line"
|
||||
import ShippingMethodAdjustment from "./shipping-method-adjustment"
|
||||
import ShippingMethodTaxLine from "./shipping-method-tax-line"
|
||||
|
||||
@Entity({ tableName: "cart_shipping_method" })
|
||||
@@ -62,13 +62,13 @@ export default class ShippingMethod {
|
||||
tax_lines = new Collection<ShippingMethodTaxLine>(this)
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingMethodAdjustmentLine,
|
||||
() => ShippingMethodAdjustment,
|
||||
(adjustment) => adjustment.shipping_method,
|
||||
{
|
||||
cascade: [Cascade.REMOVE],
|
||||
}
|
||||
)
|
||||
adjustments = new Collection<ShippingMethodAdjustmentLine>(this)
|
||||
adjustments = new Collection<ShippingMethodAdjustment>(this)
|
||||
|
||||
/** COMPUTED PROPERTIES - START */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user