feat(workflows-sdk,core-flows,medusa,types): add workflow to update promotions to cart (#6474)
what: - adds API + workflow to add/remove promotions in a cart - minor fixes in promotions module - minor type fixes in cart module - typing fix in workflows-sdk (Thanks @adrien2p) - fix step result in workflows-sdk (Thanks @adrien2p) RESOLVES CORE-1768 Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
63be07031b
commit
ac86362e81
@@ -2,12 +2,12 @@ import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
DALUtils,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
BeforeUpdate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
@@ -123,13 +123,13 @@ export default class LineItem {
|
||||
@Property({ columnType: "boolean" })
|
||||
is_tax_inclusive = false
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
@MikroOrmBigNumberProperty({ nullable: true })
|
||||
compare_at_unit_price?: BigNumber | number | null = null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
raw_compare_at_unit_price: BigNumberRawValue | null = null
|
||||
|
||||
@Property({ columnType: "numeric" })
|
||||
@MikroOrmBigNumberProperty()
|
||||
unit_price: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
@@ -171,28 +171,10 @@ export default class LineItem {
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "cali")
|
||||
|
||||
const val = new BigNumber(this.raw_unit_price ?? this.unit_price)
|
||||
|
||||
this.unit_price = val.numeric
|
||||
this.raw_unit_price = val.raw!
|
||||
}
|
||||
|
||||
@BeforeUpdate()
|
||||
onUpdate() {
|
||||
const val = new BigNumber(this.raw_unit_price ?? this.unit_price)
|
||||
|
||||
this.unit_price = val.numeric
|
||||
this.raw_unit_price = val.raw as BigNumberRawValue
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "cali")
|
||||
|
||||
const val = new BigNumber(this.raw_unit_price ?? this.unit_price)
|
||||
|
||||
this.unit_price = val.numeric
|
||||
this.raw_unit_price = val.raw!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
DALUtils,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { BeforeUpdate } from "typeorm"
|
||||
import Cart from "./cart"
|
||||
import ShippingMethodAdjustment from "./shipping-method-adjustment"
|
||||
import ShippingMethodTaxLine from "./shipping-method-tax-line"
|
||||
@@ -49,7 +49,7 @@ export default class ShippingMethod {
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Cart,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST, "soft-remove"] as any,
|
||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||
})
|
||||
cart: Cart
|
||||
|
||||
@@ -59,7 +59,7 @@ export default class ShippingMethod {
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
description: string | null = null
|
||||
|
||||
@Property({ columnType: "numeric" })
|
||||
@MikroOrmBigNumberProperty()
|
||||
amount: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
@@ -127,28 +127,10 @@ export default class ShippingMethod {
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "casm")
|
||||
|
||||
const val = new BigNumber(this.raw_amount ?? this.amount)
|
||||
|
||||
this.amount = val.numeric
|
||||
this.raw_amount = val.raw!
|
||||
}
|
||||
|
||||
@BeforeUpdate()
|
||||
onUpdate() {
|
||||
const val = new BigNumber(this.raw_amount ?? this.amount)
|
||||
|
||||
this.amount = val.numeric
|
||||
this.raw_amount = val.raw as BigNumberRawValue
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "casm")
|
||||
|
||||
const val = new BigNumber(this.raw_amount ?? this.amount)
|
||||
|
||||
this.amount = val.numeric
|
||||
this.raw_amount = val.raw!
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user