* init * add query params * added buld id validation to repo * admin done * updated price reqs * initial price selection strategy * update customer seeder * format models * price selection strategy * price selection testing * update price selection tests * update price selection strategy * remove console.warn * update price seleciton strategy * use price selection strategy in "get-product" * price selection strategy integration testing * update integration tests * update price selection strat * remove console.log * fix unit tests * update product snapshot integration tests * fix failing unit tests * update variant test snapshots * update variant test snapshots * fix failing unit tests * update product snapshot integration tests * intial implementation of PriceList * add price selection strategy test to list-products * add price selection to list products * add price selection strategy to getRegionPrice * add price selection strategy to get variant * update product snapshot test * store testing of price selection * variant services * update cart service * update product tests * update test * unit testing with price selection strategy * integration tests for price lists * update sort prices for consistent results * update snapshot * update product snapshot with product ids * this time pipelines work * swap tests * redo ordering * updated admin/product integration tests * update updateVariantPrices method * remove comment from error handler * add integration test for batch deleting prices associated with price list * named ids * run with verbose * add console.log * sort products in integration test * remove verbose flag * make update to prices through variant service limited to default prices * update store/products.js snapshot * update comment * add todo * lift existing price calculations to variant level * remove unused import * add api unit tests and update product integration tests to validate that prices from Price List are ignored * fix product test * update integration tests * pre merge commit * requested changes * cascade * ensure delete variant cascades to MoneyAmount * fetch variants correctly * use find options * add pricelist to relevant seeders * update integration tests * update price selection with "includeDiscountPrices" * use transaction with price selection strategy * add await to prevent store test errors * remove verbose * addresses PR feedback * removed unused endpoint * remove unused repository from constructor * remove from constructor argument * update mock * update unit tests * fix failing store integration tests * remove medusajs ressource * re add env.template * price selection strategy methods * fix integration tests * update unit tests * remove commented out code * update jsdoc * update price selection strategy parameter * update snapshots * integration tests cleanup * pr feedback * update integration tests * pr feedback * price selection unit tests * add calculated price type to results * cleanup include discount prices and price selection configs * refactor price selection params to a separate file * update tests and refactor price selection seeder * remove prices from variant update * rename result * pr feedback * remove unused import * create getRegionPriceContext * remove from params in search * remove unused import Co-authored-by: Kasper <kasper@medusajs.com> Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
325 lines
7.5 KiB
JavaScript
325 lines
7.5 KiB
JavaScript
const {
|
|
ProductCollection,
|
|
ProductTag,
|
|
ProductType,
|
|
ProductOption,
|
|
Region,
|
|
Product,
|
|
ShippingProfile,
|
|
ProductVariant,
|
|
Image,
|
|
} = require("@medusajs/medusa")
|
|
|
|
module.exports = async (connection, data = {}) => {
|
|
const manager = connection.manager
|
|
|
|
const defaultProfile = await manager.findOne(ShippingProfile, {
|
|
type: "default",
|
|
})
|
|
|
|
const coll = await manager.create(ProductCollection, {
|
|
id: "test-collection",
|
|
handle: "test-collection",
|
|
title: "Test collection",
|
|
})
|
|
|
|
await manager.save(coll)
|
|
|
|
const coll1 = await manager.create(ProductCollection, {
|
|
id: "test-collection1",
|
|
handle: "test-collection1",
|
|
title: "Test collection 1",
|
|
})
|
|
|
|
await manager.save(coll1)
|
|
|
|
const coll2 = await manager.create(ProductCollection, {
|
|
id: "test-collection2",
|
|
handle: "test-collection2",
|
|
title: "Test collection 2",
|
|
})
|
|
|
|
await manager.save(coll2)
|
|
|
|
const tag = await manager.create(ProductTag, {
|
|
id: "tag1",
|
|
value: "123",
|
|
})
|
|
|
|
await manager.save(tag)
|
|
|
|
const tag3 = await manager.create(ProductTag, {
|
|
id: "tag3",
|
|
value: "123",
|
|
})
|
|
|
|
await manager.save(tag3)
|
|
|
|
const tag4 = await manager.create(ProductTag, {
|
|
id: "tag4",
|
|
value: "123",
|
|
})
|
|
|
|
await manager.save(tag4)
|
|
|
|
const type = await manager.create(ProductType, {
|
|
id: "test-type",
|
|
value: "test-type",
|
|
})
|
|
|
|
await manager.save(type)
|
|
|
|
const image = manager.create(Image, {
|
|
id: "test-image",
|
|
url: "test-image.png",
|
|
})
|
|
|
|
await manager.save(image)
|
|
|
|
await manager.insert(Region, {
|
|
id: "test-region",
|
|
name: "Test Region",
|
|
currency_code: "usd",
|
|
tax_rate: 0,
|
|
})
|
|
|
|
const p = await manager.create(Product, {
|
|
id: "test-product",
|
|
handle: "test-product",
|
|
title: "Test product",
|
|
profile_id: defaultProfile.id,
|
|
description: "test-product-description",
|
|
collection_id: "test-collection",
|
|
type: { id: "test-type", value: "test-type" },
|
|
tags: [
|
|
{ id: "tag1", value: "123" },
|
|
{ tag: "tag2", value: "456" },
|
|
],
|
|
})
|
|
|
|
p.images = [image]
|
|
|
|
await manager.save(p)
|
|
|
|
await manager.save(ProductOption, {
|
|
id: "test-option",
|
|
title: "test-option",
|
|
product_id: "test-product",
|
|
})
|
|
|
|
const variant1 = await manager.create(ProductVariant, {
|
|
id: "test-variant",
|
|
inventory_quantity: 10,
|
|
title: "Test variant",
|
|
variant_rank: 0,
|
|
sku: "test-sku",
|
|
ean: "test-ean",
|
|
upc: "test-upc",
|
|
barcode: "test-barcode",
|
|
product_id: "test-product",
|
|
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
|
|
options: [
|
|
{
|
|
id: "test-variant-option",
|
|
value: "Default variant",
|
|
option_id: "test-option",
|
|
},
|
|
],
|
|
})
|
|
|
|
await manager.save(variant1)
|
|
|
|
const sale = await manager.create(ProductVariant, {
|
|
id: "test-variant-sale",
|
|
inventory_quantity: 10,
|
|
title: "Test variant",
|
|
variant_rank: 3,
|
|
sku: "test-sku-sale",
|
|
ean: "test-ean-sale",
|
|
upc: "test-upc-sale",
|
|
barcode: "test-barcode-sale",
|
|
product_id: "test-product",
|
|
prices: [
|
|
{
|
|
id: "test-price-sale",
|
|
currency_code: "usd",
|
|
amount: 1000,
|
|
},
|
|
],
|
|
options: [
|
|
{
|
|
id: "test-variant-option-sale",
|
|
value: "Default variant",
|
|
option_id: "test-option",
|
|
},
|
|
],
|
|
})
|
|
|
|
await manager.save(sale)
|
|
|
|
const variant2 = await manager.create(ProductVariant, {
|
|
id: "test-variant_1",
|
|
inventory_quantity: 10,
|
|
title: "Test variant rank (1)",
|
|
variant_rank: 2,
|
|
sku: "test-sku1",
|
|
ean: "test-ean1",
|
|
upc: "test-upc1",
|
|
barcode: "test-barcode 1",
|
|
product_id: "test-product",
|
|
prices: [{ id: "test-price1", currency_code: "usd", amount: 100 }],
|
|
options: [
|
|
{
|
|
id: "test-variant-option-1",
|
|
value: "Default variant 1",
|
|
option_id: "test-option",
|
|
},
|
|
],
|
|
})
|
|
|
|
await manager.save(variant2)
|
|
|
|
const variant3 = await manager.create(ProductVariant, {
|
|
id: "test-variant_2",
|
|
inventory_quantity: 10,
|
|
title: "Test variant rank (2)",
|
|
variant_rank: 1,
|
|
sku: "test-sku2",
|
|
ean: "test-ean2",
|
|
upc: "test-upc2",
|
|
product_id: "test-product",
|
|
prices: [{ id: "test-price2", currency_code: "usd", amount: 100 }],
|
|
options: [
|
|
{
|
|
id: "test-variant-option-2",
|
|
value: "Default variant 2",
|
|
option_id: "test-option",
|
|
},
|
|
],
|
|
})
|
|
|
|
await manager.save(variant3)
|
|
|
|
const p1 = await manager.create(Product, {
|
|
id: "test-product1",
|
|
handle: "test-product1",
|
|
title: "Test product1",
|
|
profile_id: defaultProfile.id,
|
|
description: "test-product-description1",
|
|
collection_id: "test-collection",
|
|
type: { id: "test-type", value: "test-type" },
|
|
tags: [
|
|
{ id: "tag1", value: "123" },
|
|
{ tag: "tag2", value: "456" },
|
|
],
|
|
})
|
|
|
|
await manager.save(p1)
|
|
|
|
const variant4 = await manager.create(ProductVariant, {
|
|
id: "test-variant_3",
|
|
inventory_quantity: 10,
|
|
title: "Test variant rank (2)",
|
|
variant_rank: 1,
|
|
sku: "test-sku3",
|
|
ean: "test-ean3",
|
|
upc: "test-upc3",
|
|
product_id: "test-product1",
|
|
prices: [
|
|
{
|
|
id: "test-price3",
|
|
region_id: "test-region",
|
|
currency_code: "usd",
|
|
amount: 100,
|
|
type: "default",
|
|
},
|
|
],
|
|
options: [
|
|
{
|
|
id: "test-variant-option-3",
|
|
value: "Default variant 3",
|
|
option_id: "test-option",
|
|
},
|
|
],
|
|
})
|
|
|
|
await manager.save(variant4)
|
|
|
|
const variant5 = await manager.create(ProductVariant, {
|
|
id: "test-variant_4",
|
|
inventory_quantity: 10,
|
|
title: "Test variant rank (2)",
|
|
variant_rank: 0,
|
|
sku: "test-sku4",
|
|
ean: "test-ean4",
|
|
upc: "test-upc4",
|
|
product_id: "test-product1",
|
|
prices: [
|
|
{ id: "test-price4", currency_code: "usd", amount: 100, type: "default" },
|
|
],
|
|
options: [
|
|
{
|
|
id: "test-variant-option-4",
|
|
value: "Default variant 4",
|
|
option_id: "test-option",
|
|
},
|
|
],
|
|
})
|
|
|
|
await manager.save(variant5)
|
|
|
|
const product1 = await manager.create(Product, {
|
|
id: "test-product_filtering_1",
|
|
handle: "test-product_filtering_1",
|
|
title: "Test product filtering 1",
|
|
profile_id: defaultProfile.id,
|
|
description: "test-product-description",
|
|
type: { id: "test-type", value: "test-type" },
|
|
collection_id: "test-collection1",
|
|
status: "proposed",
|
|
tags: [{ id: "tag3", value: "123" }],
|
|
})
|
|
|
|
await manager.save(product1)
|
|
|
|
const product2 = await manager.create(Product, {
|
|
id: "test-product_filtering_2",
|
|
handle: "test-product_filtering_2",
|
|
title: "Test product filtering 2",
|
|
profile_id: defaultProfile.id,
|
|
description: "test-product-description",
|
|
type: { id: "test-type", value: "test-type" },
|
|
collection_id: "test-collection2",
|
|
status: "published",
|
|
tags: [{ id: "tag3", value: "123" }],
|
|
})
|
|
|
|
await manager.save(product2)
|
|
|
|
const product3 = await manager.create(Product, {
|
|
id: "test-product_filtering_3",
|
|
handle: "test-product_filtering_3",
|
|
title: "Test product filtering 3",
|
|
profile_id: defaultProfile.id,
|
|
description: "test-product-description",
|
|
type: { id: "test-type", value: "test-type" },
|
|
collection_id: "test-collection1",
|
|
status: "draft",
|
|
tags: [{ id: "tag4", value: "1234" }],
|
|
})
|
|
|
|
await manager.save(product3)
|
|
|
|
const product4 = await manager.create(Product, {
|
|
id: "test-product_filtering_4",
|
|
handle: "test-product_filtering_4",
|
|
title: "Test product filtering 4",
|
|
profile_id: defaultProfile.id,
|
|
description: "test-product-description",
|
|
status: "proposed",
|
|
deleted_at: new Date().toISOString(),
|
|
})
|
|
|
|
await manager.save(product4)
|
|
}
|