1+ function isSpecialPriceActive ( fromDate , toDate ) {
2+ const now = new Date ( )
3+ fromDate = new Date ( fromDate ) || false
4+ toDate = new Date ( toDate ) || false
5+
6+ if ( fromDate && toDate ) {
7+ return fromDate < now && toDate > now
8+ }
9+
10+ if ( fromDate && ! toDate ) {
11+ return fromDate < now
12+ }
13+
14+ if ( ! fromDate && toDate ) {
15+ return toDate > now
16+ }
17+ }
18+
119export function updateProductPrices ( product , rate , sourcePriceInclTax = false ) {
220 const rateFactor = parseFloat ( rate . rate ) / 100
321 product . price = parseFloat ( product . price )
@@ -22,7 +40,7 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
2240 product . specialPriceInclTax = specialPriceExclTax + product . specialPriceTax
2341
2442 if ( product . special_price && ( product . special_price < product . price ) ) {
25- if ( ( product . special_to_date && new Date ( product . special_to_date ) < new Date ( ) ) || ( product . special_from_date && new Date ( product . special_from_date ) > new Date ( ) ) ) {
43+ if ( ! isSpecialPriceActive ( product . special_from_date , product . special_to_date ) ) {
2644 product . special_price = 0 // out of the dates period
2745 } else {
2846 product . originalPrice = priceExclTax
@@ -67,7 +85,7 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false)
6785 configurableChild . specialPriceInclTax = specialPriceExclTax + configurableChild . specialPriceTax
6886
6987 if ( configurableChild . special_price && ( configurableChild . special_price < configurableChild . price ) ) {
70- if ( ( configurableChild . special_to_date && new Date ( configurableChild . special_to_date ) < new Date ( ) ) || ( configurableChild . special_from_date && new Date ( configurableChild . special_from_date ) > new Date ( ) ) ) {
88+ if ( ! isSpecialPriceActive ( configurableChild . special_from_date , configurableChild . special_to_date ) ) {
7189 configurableChild . special_price = 0 // out of the dates period
7290 } else {
7391 configurableChild . originalPrice = priceExclTax
0 commit comments