Skip to content

Commit

Permalink
[-] FO : Fix discount display issues #PSCSX-3308
Browse files Browse the repository at this point in the history
  • Loading branch information
tchauviere committed Sep 11, 2014
1 parent 7f966ae commit 867abe5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
7 changes: 7 additions & 0 deletions controllers/front/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,19 @@ public function displayAjax()
false,
false
);

if ($product['reduction_type'] == 'amount')
{
$reduction = (float)$product['price_wt'] - (float)$product['price_without_quantity_discount'];
$product['reduction_formatted'] = Tools::displayPrice($reduction);
}
}
if ($result['customizedDatas'])
Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']);

Hook::exec('actionCartListOverride', array('summary' => $result, 'json' => &$json));
die(Tools::jsonEncode(array_merge($result, (array)Tools::jsonDecode($json, true))));

}
// @todo create a hook
elseif (file_exists(_PS_MODULE_DIR_.'/blockcart/blockcart-ajax.php'))
Expand Down
18 changes: 15 additions & 3 deletions themes/default-bootstrap/js/cart-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,13 @@ function updateCartSummary(json)
{
// if reduction, we need to show it in the cart by showing the initial price above the current one
var reduction = product_list[i].reduction_applies;
var reduction_type = product_list[i].reduction_type;
var reduction_symbol = '';
var initial_price_text = '';
initial_price = '';

if (typeof(product_list[i].price_without_quantity_discount) !== 'undefined')
initial_price = formatCurrency(product_list[i].price_without_quantity_discount, currencyFormat, currencySign, currencyBlank);
priceReductionPercent = ps_round((ps_round(product_list[i].price_without_quantity_discount) - ps_round(product_list[i].price_wt))/ps_round(product_list[i].price_without_quantity_discount) * -100);

var current_price = '';
var product_total = '';
Expand All @@ -795,16 +797,26 @@ function updateCartSummary(json)

var current_price_class ='price';
if (reduction && typeof(initial_price) !== 'undefined')
{
if (reduction_type == 'amount')
price_reduction = product_list[i].reduction_formatted;
else
{
price_reduction = ps_round((ps_round(product_list[i].price_without_quantity_discount) - ps_round(product_list[i].price_wt))/ps_round(product_list[i].price_without_quantity_discount) * -100);
reduction_symbol = '%';
}

if (initial_price !== '' && product_list[i].price_without_quantity_discount > product_list[i].price)
{
initial_price_text = '<span class="price-percent-reduction small">'+priceReductionPercent+'%</span><span class="old-price">' + initial_price + '</span>';
initial_price_text = '<li class="price-percent-reduction small">&nbsp;'+price_reduction+reduction_symbol+'&nbsp;</li><li class="old-price">' + initial_price + '</li>';
current_price_class += ' special-price';
}
}

var key_for_blockcart = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + product_list[i].id_address_delivery;
var key_for_blockcart_nocustom = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + ((product_list[i].id_customization && product_list[i].quantity_without_customization != product_list[i].quantity)? 'nocustom' : '0') + '_' + product_list[i].id_address_delivery;

$('#product_price_' + key_for_blockcart).html('<span class="' + current_price_class + '">' + current_price + '</span>' + initial_price_text);
$('#product_price_' + key_for_blockcart).html('<li class="' + current_price_class + '">' + current_price + '</li>' + initial_price_text);
if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
$('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_customization_total, currencyFormat, currencySign, currencyBlank));
else
Expand Down
18 changes: 9 additions & 9 deletions themes/default-bootstrap/shopping-cart-product-line.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
<td class="cart_avail"><span class="{if $product.quantity_available <= 0 && !$product.allow_oosp}label label-warning{else}label label-success{/if}">{if $product.quantity_available <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}</span>{hook h="displayProductDeliveryTime" product=$product}</td>
{/if}
<td class="cart_unit" data-title="{l s='Unit price'}">
<span class="price" id="product_price_{$product.id_product}_{$product.id_product_attribute}{if $quantityDisplayed > 0}_nocustom{/if}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}">
<ul class="price text-center" id="product_price_{$product.id_product}_{$product.id_product_attribute}{if $quantityDisplayed > 0}_nocustom{/if}_{$product.id_address_delivery|intval}{if !empty($product.gift)}_gift{/if}">
{if !empty($product.gift)}
<span class="gift-icon">{l s='Gift!'}</span>
<li class="gift-icon">{l s='Gift!'}</li>
{else}
{if !$priceDisplay}
<span class="price{if isset($product.is_discounted) && $product.is_discounted} special-price{/if}">{convertPrice price=$product.price_wt}</span>
<li class="price{if isset($product.is_discounted) && $product.is_discounted} special-price{/if}">{convertPrice price=$product.price_wt}</li>
{else}
<span class="price{if isset($product.is_discounted) && $product.is_discounted} special-price{/if}">{convertPrice price=$product.price}</span>
<li class="price{if isset($product.is_discounted) && $product.is_discounted} special-price{/if}">{convertPrice price=$product.price}</li>
{/if}
{if isset($product.is_discounted) && $product.is_discounted}
<span class="price-percent-reduction small">
<li class="price-percent-reduction small">
{if !$priceDisplay}
{if isset($product.reduction_type) && $product.reduction_type == 'amount'}
{assign var='priceReduction' value=($product.price_wt - $product.price_without_specific_price)}
Expand All @@ -66,13 +66,13 @@
{if $symbol == '%'}
&nbsp;{$priceReduction|round|string_format:"%d"}{$symbol}&nbsp;
{else}
&nbsp;{$priceReduction|string_format:"%.2f"}{$symbol}&nbsp;
&nbsp;{convertPrice price=$priceReduction}&nbsp;
{/if}
</span>
<span class="old-price">{convertPrice price=$product.price_without_specific_price}</span>
</li>
<li class="old-price">{convertPrice price=$product.price_without_specific_price}</li>
{/if}
{/if}
</span>
</ul>
</td>

<td class="cart_quantity text-center">
Expand Down
2 changes: 1 addition & 1 deletion themes/default-bootstrap/shopping-cart.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
{else}
{assign var='col_span_subtotal' value='2'}
{/if}
<th class="cart_unit item text-right">{l s='Unit price'}</th>
<th class="cart_unit item">{l s='Unit price'}</th>
<th class="cart_quantity item text-center">{l s='Qty'}</th>
<th class="cart_delete last_item">&nbsp;</th>
<th class="cart_total item text-right">{l s='Total'}</th>
Expand Down

0 comments on commit 867abe5

Please sign in to comment.