fix: Use correct product price when fetching product for pricelist (#1416)

This commit is contained in:
Philip Korsholm
2022-05-08 13:03:29 +02:00
committed by GitHub
parent 3c75a65792
commit e2d08316dd
5 changed files with 216 additions and 22 deletions
@@ -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)