fix: Use correct product price when fetching product for pricelist (#1416)
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
MoneyAmount,
|
||||
PriceListType,
|
||||
PriceListStatus,
|
||||
CustomerGroup,
|
||||
} from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
@@ -38,6 +39,28 @@ export const simplePriceListFactory = async (
|
||||
const manager = connection.manager
|
||||
|
||||
const listId = data.id || `simple-price-list-${Math.random() * 1000}`
|
||||
|
||||
let customerGroups = []
|
||||
if (typeof data.customer_groups !== "undefined") {
|
||||
await manager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(CustomerGroup)
|
||||
.values(
|
||||
data.customer_groups.map((group) => ({
|
||||
id: group,
|
||||
name: faker.company.companyName(),
|
||||
}))
|
||||
)
|
||||
.orIgnore()
|
||||
.execute()
|
||||
|
||||
customerGroups = await manager.findByIds(
|
||||
CustomerGroup,
|
||||
data.customer_groups
|
||||
)
|
||||
}
|
||||
|
||||
const toCreate = {
|
||||
id: listId,
|
||||
name: data.name || faker.commerce.productName(),
|
||||
@@ -46,6 +69,7 @@ export const simplePriceListFactory = async (
|
||||
type: data.type || PriceListType.OVERRIDE,
|
||||
starts_at: data.starts_at || null,
|
||||
ends_at: data.ends_at || null,
|
||||
customer_groups: customerGroups,
|
||||
}
|
||||
|
||||
const toSave = manager.create(PriceList, toCreate)
|
||||
|
||||
Reference in New Issue
Block a user