fix: Return null for calculated price if no prices are defined (#7886)
This commit is contained in:
+21
-576
@@ -288,6 +288,25 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("calculating prices when listing price sets should return null when there are no prices", async () => {
|
||||||
|
const [newSet] = await service.createPriceSets([{}])
|
||||||
|
const calculatePricesResult = await service.calculatePrices(
|
||||||
|
{ id: [newSet.id] },
|
||||||
|
{ context: { currency_code: "PLN" } }
|
||||||
|
)
|
||||||
|
|
||||||
|
const priceSetsResult = await service.listPriceSets(
|
||||||
|
{
|
||||||
|
id: [newSet.id],
|
||||||
|
context: { currency_code: "PLN" },
|
||||||
|
},
|
||||||
|
{ relations: ["calculated_price"] }
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(calculatePricesResult).toEqual([])
|
||||||
|
expect(priceSetsResult[0].calculated_price).toEqual(null)
|
||||||
|
})
|
||||||
|
|
||||||
it("should return filled prices when 1 context is present and price is setup for PLN", async () => {
|
it("should return filled prices when 1 context is present and price is setup for PLN", async () => {
|
||||||
const priceSetsResult = await service.calculatePrices(
|
const priceSetsResult = await service.calculatePrices(
|
||||||
{ id: ["price-set-EUR", "price-set-PLN"] },
|
{ id: ["price-set-EUR", "price-set-PLN"] },
|
||||||
@@ -297,28 +316,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -353,28 +350,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -409,28 +384,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -464,52 +417,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([])
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "price-set-PLN",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return filled prices when 2 contexts are present and price is setup", async () => {
|
it("should return filled prices when 2 contexts are present and price is setup", async () => {
|
||||||
@@ -521,28 +429,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -577,28 +463,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -672,28 +536,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -733,28 +575,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Currency Code + Region value + customer group id
|
// Currency Code + Region value + customer group id
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
@@ -795,28 +615,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// PLN price set is not setup for EUR currency_code so it will default to a null set
|
// PLN price set is not setup for EUR currency_code so it will default to a null set
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
@@ -857,28 +655,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// PLN price set is not setup for EUR currency_code so it will default to a null set
|
// PLN price set is not setup for EUR currency_code so it will default to a null set
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
@@ -913,52 +689,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([])
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "price-set-PLN",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return filled prices when 2 context is present and prices are setup, but only for one of the contexts", async () => {
|
it("should return filled prices when 2 context is present and prices are setup, but only for one of the contexts", async () => {
|
||||||
@@ -974,28 +705,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -1038,28 +747,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1109,28 +796,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1172,28 +837,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1232,28 +875,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1295,28 +916,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1357,28 +956,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -1419,28 +996,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -1494,28 +1049,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1570,28 +1103,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -1645,28 +1156,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: false,
|
is_calculated_price_price_list: false,
|
||||||
@@ -1773,28 +1262,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
@@ -1846,28 +1313,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(priceSetsResult).toEqual([
|
expect(priceSetsResult).toEqual([
|
||||||
{
|
|
||||||
id: "price-set-EUR",
|
|
||||||
is_calculated_price_price_list: false,
|
|
||||||
calculated_amount: null,
|
|
||||||
is_original_price_price_list: false,
|
|
||||||
original_amount: null,
|
|
||||||
currency_code: null,
|
|
||||||
calculated_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
original_price: {
|
|
||||||
id: null,
|
|
||||||
price_list_id: null,
|
|
||||||
price_list_type: null,
|
|
||||||
min_quantity: null,
|
|
||||||
max_quantity: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "price-set-PLN",
|
id: "price-set-PLN",
|
||||||
is_calculated_price_price_list: true,
|
is_calculated_price_price_list: true,
|
||||||
|
|||||||
@@ -144,21 +144,20 @@ export default class PricingModuleService
|
|||||||
return priceSets
|
return priceSets
|
||||||
}
|
}
|
||||||
|
|
||||||
const priceSetIds: string[] = []
|
|
||||||
const priceSetMap = new Map()
|
|
||||||
for (const priceSet of priceSets) {
|
|
||||||
priceSetIds.push(priceSet.id)
|
|
||||||
priceSetMap.set(priceSet.id, priceSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
const calculatedPrices = await this.calculatePrices(
|
const calculatedPrices = await this.calculatePrices(
|
||||||
{ id: priceSetIds },
|
{ id: priceSets.map((p) => p.id) },
|
||||||
{ context: pricingContext },
|
{ context: pricingContext },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const calculatedPricesMap = new Map()
|
||||||
for (const calculatedPrice of calculatedPrices) {
|
for (const calculatedPrice of calculatedPrices) {
|
||||||
const priceSet = priceSetMap.get(calculatedPrice.id)
|
calculatedPricesMap.set(calculatedPrice.id, calculatedPrice)
|
||||||
priceSet.calculated_price = calculatedPrice
|
}
|
||||||
|
|
||||||
|
for (const priceSet of priceSets) {
|
||||||
|
const calculatedPrice = calculatedPricesMap.get(priceSet.id)
|
||||||
|
priceSet.calculated_price = calculatedPrice ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
return priceSets
|
return priceSets
|
||||||
@@ -182,21 +181,20 @@ export default class PricingModuleService
|
|||||||
return [priceSets, count]
|
return [priceSets, count]
|
||||||
}
|
}
|
||||||
|
|
||||||
const priceSetIds: string[] = []
|
|
||||||
const priceSetMap = new Map()
|
|
||||||
for (const priceSet of priceSets) {
|
|
||||||
priceSetIds.push(priceSet.id)
|
|
||||||
priceSetMap.set(priceSet.id, priceSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
const calculatedPrices = await this.calculatePrices(
|
const calculatedPrices = await this.calculatePrices(
|
||||||
{ id: priceSetIds },
|
{ id: priceSets.map((p) => p.id) },
|
||||||
{ context: pricingContext },
|
{ context: pricingContext },
|
||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const calculatedPricesMap = new Map()
|
||||||
for (const calculatedPrice of calculatedPrices) {
|
for (const calculatedPrice of calculatedPrices) {
|
||||||
const priceSet = priceSetMap.get(calculatedPrice.id)
|
calculatedPricesMap.set(calculatedPrice.id, calculatedPrice)
|
||||||
priceSet.calculated_price = calculatedPrice
|
}
|
||||||
|
|
||||||
|
for (const priceSet of priceSets) {
|
||||||
|
const calculatedPrice = calculatedPricesMap.get(priceSet.id)
|
||||||
|
priceSet.calculated_price = calculatedPrice ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
return [priceSets, count]
|
return [priceSets, count]
|
||||||
@@ -217,14 +215,18 @@ export default class PricingModuleService
|
|||||||
const pricesSetPricesMap = groupBy(results, "price_set_id")
|
const pricesSetPricesMap = groupBy(results, "price_set_id")
|
||||||
|
|
||||||
const calculatedPrices: PricingTypes.CalculatedPriceSet[] =
|
const calculatedPrices: PricingTypes.CalculatedPriceSet[] =
|
||||||
pricingFilters.id.map(
|
pricingFilters.id
|
||||||
(priceSetId: string): PricingTypes.CalculatedPriceSet => {
|
.map((priceSetId: string): PricingTypes.CalculatedPriceSet | null => {
|
||||||
// This is where we select prices, for now we just do a first match based on the database results
|
// This is where we select prices, for now we just do a first match based on the database results
|
||||||
// which is prioritized by rules_count first for exact match and then deafult_priority of the rule_type
|
// which is prioritized by rules_count first for exact match and then deafult_priority of the rule_type
|
||||||
|
|
||||||
// TODO: inject custom price selection here
|
// TODO: inject custom price selection here
|
||||||
|
|
||||||
const prices = pricesSetPricesMap.get(priceSetId) || []
|
const prices = pricesSetPricesMap.get(priceSetId) || []
|
||||||
|
if (!prices.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const priceListPrice = prices.find((p) => p.price_list_id)
|
const priceListPrice = prices.find((p) => p.price_list_id)
|
||||||
|
|
||||||
const defaultPrice = prices?.find((p) => !p.price_list_id)
|
const defaultPrice = prices?.find((p) => !p.price_list_id)
|
||||||
@@ -268,8 +270,8 @@ export default class PricingModuleService
|
|||||||
max_quantity: parseInt(originalPrice?.max_quantity || "") || null,
|
max_quantity: parseInt(originalPrice?.max_quantity || "") || null,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
.filter(Boolean) as PricingTypes.CalculatedPriceSet[]
|
||||||
|
|
||||||
return JSON.parse(JSON.stringify(calculatedPrices))
|
return JSON.parse(JSON.stringify(calculatedPrices))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user