Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit e700164

Browse files
authored
Merge pull request #375 from afirlejczyk/bugfix/configurable-final-price
Fixes for calculating lowest price after refactoring.
2 parents 74e4ce0 + 1cf6377 commit e700164

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/lib/taxcalc.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function updateProductPrices ({ product, rate, sourcePriceInclTax = false
7272
product.hasOwnProperty('original_final_price') &&
7373
product.hasOwnProperty('original_special_price')
7474
)
75+
7576
// build objects with original price and tax
7677
// for first calculation use `price`, for next one use `original_price`
7778
const priceWithTax = createSinglePrice(parseFloat(product.original_price || product.price), rate_factor, sourcePriceInclTax && !hasOriginalPrices)
@@ -81,24 +82,30 @@ export function updateProductPrices ({ product, rate, sourcePriceInclTax = false
8182
// save original prices
8283
if (!hasOriginalPrices) {
8384
assignPrice({product, target: 'original_price', ...priceWithTax, deprecatedPriceFieldsSupport})
84-
85-
product.original_final_price = finalPriceWithTax.price
86-
product.original_special_price = specialPriceWithTax.price
85+
if (specialPriceWithTax.price) {
86+
product.original_special_price = specialPriceWithTax.price
87+
}
88+
if (finalPriceWithTax.price) {
89+
product.original_final_price = finalPriceWithTax.price
90+
}
8791
}
8892

8993
// reset previous calculation
9094
assignPrice({product, target: 'price', ...priceWithTax, deprecatedPriceFieldsSupport})
91-
assignPrice({product, target: 'final_price', ...finalPriceWithTax, deprecatedPriceFieldsSupport})
92-
assignPrice({product, target: 'special_price', ...specialPriceWithTax, deprecatedPriceFieldsSupport})
95+
if (specialPriceWithTax.price) {
96+
assignPrice({product, target: 'special_price', ...specialPriceWithTax, deprecatedPriceFieldsSupport})
97+
}
98+
if (finalPriceWithTax.price) {
99+
assignPrice({product, target: 'final_price', ...finalPriceWithTax, deprecatedPriceFieldsSupport})
100+
}
93101

94102
if (product.final_price) {
95103
if (product.final_price < product.price) { // compare the prices with the product final price if provided; final prices is used in case of active catalog promo rules for example
104+
assignPrice({product, target: 'price', price: product.final_price, deprecatedPriceFieldsSupport})
96105
if (product.final_price < product.special_price) { // for VS - special_price is any price lowered than regular price (`price`); in Magento there is a separate mechanism for setting the `special_prices`
97-
assignPrice({product, target: 'price', ...specialPriceWithTax, deprecatedPriceFieldsSupport}) // if the `final_price` is lower than the original `special_price` - it means some catalog rules were applied over it
106+
assignPrice({product, target: 'price', price: product.special_price, deprecatedPriceFieldsSupport}) // if the `final_price` is lower than the original `special_price` - it means some catalog rules were applied over it
98107
}
99-
assignPrice({product, target: 'special_price', ...finalPriceWithTax, deprecatedPriceFieldsSupport})
100-
} else {
101-
assignPrice({product, target: 'price', ...finalPriceWithTax, deprecatedPriceFieldsSupport})
108+
assignPrice({product, target: 'special_price', price: product.final_price, deprecatedPriceFieldsSupport})
102109
}
103110
}
104111

@@ -107,7 +114,7 @@ export function updateProductPrices ({ product, rate, sourcePriceInclTax = false
107114
// out of the dates period
108115
assignPrice({product, target: 'special_price', price: 0, tax: 0, deprecatedPriceFieldsSupport})
109116
} else {
110-
assignPrice({product, target: 'price', ...specialPriceWithTax, deprecatedPriceFieldsSupport})
117+
assignPrice({product, target: 'price', price: product.special_price, deprecatedPriceFieldsSupport})
111118
}
112119
} else {
113120
// the same price as original; it's not a promotion

0 commit comments

Comments
 (0)