[-] FO: Fix #PSCFV-8722 displayed specific prices on product page was sometimes wrong
This commit is contained in:
@@ -458,6 +458,10 @@ class ProductCore extends ObjectModel
|
||||
$this->tax_rate = $this->getTaxesRate(new Address($address));
|
||||
|
||||
$this->new = $this->isNew();
|
||||
|
||||
// keep base price
|
||||
$this->base_price = $this->price;
|
||||
|
||||
$this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
|
||||
$this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0);
|
||||
if ($this->id)
|
||||
|
||||
@@ -295,17 +295,27 @@ function updateDisplay()
|
||||
var priceTaxExclWithoutGroupReduction = '';
|
||||
|
||||
// retrieve price without group_reduction in order to compute the group reduction after
|
||||
// the specific price discount (done in the JS in order to keep backward compatibility)
|
||||
if (!displayPrice && !noTaxForThisProduct)
|
||||
{
|
||||
priceTaxExclWithoutGroupReduction = ps_round(productPriceTaxExcluded, 6) * (1 / group_reduction);
|
||||
} else {
|
||||
priceTaxExclWithoutGroupReduction = ps_round(productPriceTaxExcluded, 6) * (1 / group_reduction);
|
||||
}
|
||||
var combination_add_price = selectedCombination['price'] * group_reduction;
|
||||
// the specific price discount (done in the JS in order to keep backward compatibility) priceTaxExclWithoutGroupReduction = ps_round(productPriceTaxExcluded, 6) * (1 / group_reduction);
|
||||
|
||||
var tax = (taxRate / 100) + 1;
|
||||
var taxExclPrice = priceTaxExclWithoutGroupReduction + (selectedCombination['price'] * currencyRate);
|
||||
|
||||
if (selectedCombination.specific_price && selectedCombination.specific_price['id_product_attribute'])
|
||||
{
|
||||
if (selectedCombination.specific_price['price'] && selectedCombination.specific_price['price'] >=0)
|
||||
var taxExclPrice = (specific_currency ? selectedCombination.specific_price['price'] : selectedCombination.specific_price['price'] * currencyRate);
|
||||
else
|
||||
var taxExclPrice = productBasePriceTaxExcluded * currencyRate + (selectedCombination['price'] * currencyRate);
|
||||
}
|
||||
else if (product_specific_price.price && product_specific_price.price >= 0)
|
||||
var taxExclPrice = (specific_currency ? product_specific_price.price : product_specific_price.price * currencyRate) + (selectedCombination['price'] * currencyRate);
|
||||
|
||||
if (!displayPrice && !noTaxForThisProduct)
|
||||
productPriceDisplay = taxExclPrice * tax; // Need to be global => no var
|
||||
else
|
||||
productPriceDisplay = ps_round(taxExclPrice, 2); // Need to be global => no var
|
||||
|
||||
productPriceWithoutReductionDisplay = productPriceDisplay * group_reduction;
|
||||
var reduction = 0;
|
||||
if (selectedCombination['specific_price'].reduction_price || selectedCombination['specific_price'].reduction_percent)
|
||||
{
|
||||
@@ -313,18 +323,26 @@ function updateDisplay()
|
||||
reduction = productPriceDisplay * (parseFloat(selectedCombination['specific_price'].reduction_percent) / 100) + reduction_price;
|
||||
if (reduction_price && (displayPrice || noTaxForThisProduct))
|
||||
reduction = ps_round(reduction / tax, 6);
|
||||
|
||||
}
|
||||
else if (product_specific_price.reduction_price || product_specific_price.reduction_percent)
|
||||
else if (product_specific_price && product_specific_price.reduction)
|
||||
{
|
||||
reduction_price = (specific_currency ? product_specific_price.reduction_price : product_specific_price.reduction_price * currencyRate);
|
||||
reduction = productPriceDisplay * (parseFloat(product_specific_price.reduction_percent) / 100) + reduction_price;
|
||||
if (product_specific_price.reduction_type == 'amount')
|
||||
reduction_price = (specific_currency ? product_specific_price.reduction : product_specific_price.reduction * currencyRate);
|
||||
else
|
||||
reduction_price = 0;
|
||||
|
||||
if (product_specific_price.reduction_type == 'percentage')
|
||||
reduction_percent = productPriceDisplay * parseFloat(product_specific_price.reduction);
|
||||
|
||||
reduction = reduction_price + reduction_percent;
|
||||
if (reduction_price && (displayPrice || noTaxForThisProduct))
|
||||
reduction = ps_round(reduction / tax, 6);
|
||||
}
|
||||
|
||||
if (selectedCombination.specific_price)
|
||||
{
|
||||
if (selectedCombination['specific_price'].reduction_type == 'percentage')
|
||||
if (selectedCombination['specific_price'] && selectedCombination['specific_price'].reduction_type == 'percentage')
|
||||
{
|
||||
$('#reduction_amount').hide();
|
||||
$('#reduction_percent_display').html('-' + parseFloat(selectedCombination['specific_price'].reduction_percent) + '%');
|
||||
@@ -338,36 +356,20 @@ function updateDisplay()
|
||||
$('#reduction_amount').hide();
|
||||
}
|
||||
}
|
||||
else
|
||||
if (product_specific_price['reduction_type'] == 'percentage')
|
||||
$('#reduction_percent_display').html(product_specific_price['specific_price'].reduction_percent);
|
||||
|
||||
if (product_specific_price['reduction_type'] != '' || selectedCombination['specific_price'].reduction_type != '')
|
||||
$('#discount_reduced_price,#old_price').show();
|
||||
else
|
||||
$('#discount_reduced_price,#old_price').hide();
|
||||
|
||||
if (product_specific_price['reduction_type'] == 'percentage' || selectedCombination['specific_price'].reduction_type == 'percentage')
|
||||
if ((product_specific_price['reduction_type'] == 'percentage' && selectedCombination['specific_price'].reduction_type == 'percentage') || selectedCombination['specific_price'].reduction_type == 'percentage')
|
||||
$('#reduction_percent').show();
|
||||
else
|
||||
$('#reduction_percent').hide();
|
||||
if (product_specific_price['price'] || selectedCombination.specific_price['price'])
|
||||
if (product_specific_price['price'] || (selectedCombination.specific_price && selectedCombination.specific_price['price']))
|
||||
$('#not_impacted_by_discount').show();
|
||||
else
|
||||
$('#not_impacted_by_discount').hide();
|
||||
|
||||
if (selectedCombination.specific_price['price'] && selectedCombination.specific_price['price'] >=0)
|
||||
var taxExclPrice = (specific_currency ? selectedCombination.specific_price['price'] : selectedCombination.specific_price['price'] * currencyRate);
|
||||
else
|
||||
var taxExclPrice = priceTaxExclWithoutGroupReduction + (selectedCombination['price'] * currencyRate);
|
||||
|
||||
if (!displayPrice && !noTaxForThisProduct)
|
||||
productPriceDisplay = taxExclPrice * tax; // Need to be global => no var
|
||||
else
|
||||
productPriceDisplay = ps_round(taxExclPrice, 2); // Need to be global => no var
|
||||
|
||||
productPriceWithoutReductionDisplay = productPriceDisplay * group_reduction;
|
||||
|
||||
productPriceDisplay -= reduction;
|
||||
var tmp = productPriceDisplay * group_reduction;
|
||||
productPriceDisplay = ps_round(productPriceDisplay * group_reduction, 2);
|
||||
@@ -719,4 +721,4 @@ function checkUrl()
|
||||
window.location = url.substring(0, url.indexOf('#'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ var allowBuyWhenOutOfStock = {if $allow_oosp == 1}true{else}false{/if};
|
||||
var availableNowValue = '{$product->available_now|escape:'quotes':'UTF-8'}';
|
||||
var availableLaterValue = '{$product->available_later|escape:'quotes':'UTF-8'}';
|
||||
var productPriceTaxExcluded = {$product->getPriceWithoutReduct(true)|default:'null'} - {$product->ecotax};
|
||||
var productBasePriceTaxExcluded = {$product->base_price} - {$product->ecotax};
|
||||
|
||||
var reduction_percent = {if $product->specificPrice AND $product->specificPrice.reduction AND $product->specificPrice.reduction_type == 'percentage'}{$product->specificPrice.reduction*100}{else}0{/if};
|
||||
var reduction_price = {if $product->specificPrice AND $product->specificPrice.reduction AND $product->specificPrice.reduction_type == 'amount'}{$product->specificPrice.reduction|floatval}{else}0{/if};
|
||||
var specific_price = {if $product->specificPrice AND $product->specificPrice.price}{$product->specificPrice.price}{else}0{/if};
|
||||
@@ -132,6 +134,7 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving
|
||||
specific_price_combination['reduction_price'] = {if $combination.specific_price AND $combination.specific_price.reduction AND $combination.specific_price.reduction_type == 'amount'}{$combination.specific_price.reduction}{else}0{/if};
|
||||
specific_price_combination['price'] = {if $combination.specific_price AND $combination.specific_price.price}{$combination.specific_price.price}{else}0{/if};
|
||||
specific_price_combination['reduction_type'] = '{if $combination.specific_price}{$combination.specific_price.reduction_type}{/if}';
|
||||
specific_price_combination['id_product_attribute'] = {if $combination.specific_price}{$combination.specific_price.id_product_attribute|intval}{else}0{/if};
|
||||
available_date['date'] = '{$combination.available_date}';
|
||||
available_date['date_formatted'] = '{dateFormat date=$combination.available_date full=false}';
|
||||
addCombination({$idCombination|intval}, new Array({$combination.list}), {$combination.quantity}, {$combination.price}, {$combination.ecotax}, {$combination.id_image}, '{$combination.reference|addslashes}', {$combination.unit_impact}, {$combination.minimal_quantity}, available_date, specific_price_combination);
|
||||
@@ -400,14 +403,14 @@ var fieldRequired = '{l s='Please fill in all the required fields before saving
|
||||
{/if}
|
||||
</div>
|
||||
<p id="reduction_percent" {if !$product->specificPrice OR $product->specificPrice.reduction_type != 'percentage'} style="display:none;"{/if}><span id="reduction_percent_display">{if $product->specificPrice AND $product->specificPrice.reduction_type == 'percentage'}-{$product->specificPrice.reduction*100}%{/if}</span></p>
|
||||
<p id="reduction_amount" {if !$product->specificPrice OR $product->specificPrice.reduction_type != 'amount' && $product->specificPrice.reduction|intval ==0} style="display:none"{/if}>
|
||||
<p id="reduction_amount" {if !$product->specificPrice OR $product->specificPrice.reduction_type != 'amount' || $product->specificPrice.reduction|intval ==0} style="display:none"{/if}>
|
||||
<span id="reduction_amount_display">
|
||||
{if $product->specificPrice AND $product->specificPrice.reduction_type == 'amount' AND $product->specificPrice.reduction|intval !=0}
|
||||
-{convertPrice price=$productPriceWithoutReduction-$productPrice|floatval}
|
||||
{/if}
|
||||
</span>
|
||||
</p>
|
||||
{if $product->specificPrice AND $product->specificPrice.reduction}
|
||||
{if $product->specificPrice AND $product->specificPrice.reduction && $product->specificPrice.reduction > 0}
|
||||
<p id="old_price"><span class="bold">
|
||||
{if $priceDisplay >= 0 && $priceDisplay <= 2}
|
||||
{if $productPriceWithoutReduction > $productPrice}
|
||||
|
||||
Reference in New Issue
Block a user