[*] FO : display initial price in the cart when a specific price is applied to a product

This commit is contained in:
vChabot
2011-09-15 12:37:44 +00:00
parent 14004d9f97
commit 875d5488e6
6 changed files with 45 additions and 12 deletions
+1 -1
View File
@@ -97,7 +97,7 @@
'FrontControllerCore' => 'classes/FrontController.php',
'FrontController' => 'override/classes/FrontController.php',
'GenderCore' => 'classes/Gender.php',
'Gender' => '',
'Gender' => 'override/classes/Gender.php',
'GroupCore' => 'classes/Group.php',
'Group' => 'override/classes/Group.php',
'GroupReductionCore' => 'classes/GroupReduction.php',
+2 -1
View File
@@ -484,6 +484,7 @@ class CartCore extends ObjectModel
$row = array_merge($row, $row2);
$row['reduction_applies'] = ($specificPriceOutput AND (float)$specificPriceOutput['reduction']);
$row['quantity_discount_applies'] = ($specificPriceOutput AND $row['cart_quantity'] >= (int)$specificPriceOutput['from_quantity']);
$row['id_image'] = Product::defineProductImage($row,$this->id_lang);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
$row['features'] = Product::getFeaturesStatic((int)$row['id_product']);
@@ -1448,7 +1449,7 @@ class CartCore extends ObjectModel
*
* @return array Cart details
*/
function getSummaryDetails($id_lang = null)
public function getSummaryDetails($id_lang = null)
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
+4
View File
@@ -55,6 +55,10 @@ class CartControllerCore extends FrontController
$result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true);
$result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']);
$result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']);
// Display reduced price (or not) without quantity discount
if (Tools::getIsset('getproductprice'))
foreach ($result['summary']['products'] as $key => $product)
$result['summary']['products'][$key]['price_without_quantity_discount'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute']);
die(Tools::jsonEncode($result));
}
else
+6 -3
View File
@@ -261,9 +261,12 @@ class ParentOrderControllerCore extends FrontController
}
$this->context->smarty->assign('free_ship', $total_free_ship);
}
// for compatibility with 1.2 themes
foreach($summary['products'] AS $key => $product)
$summary['products'][$key]['quantity'] = $product['cart_quantity'];
foreach ($summary['products'] AS $key => $product)
{
$summary['products'][$key]['quantity'] = $product['cart_quantity'];// for compatibility with 1.2 themes
$std_product = new Product($summary['products'][$key]['id_product']);
$summary['products'][$key]['price_without_specific_price'] = $std_product->getPrice(!Product::getTaxCalculationMethod(), $summary['products'][$key]['id_product_attribute']);
}
$this->context->smarty->assign($summary);
$this->context->smarty->assign(array(
+21 -6
View File
@@ -150,7 +150,7 @@ function upQuantity(id, qty)
async: true,
cache: false,
dataType: 'json',
data: 'ajax=true&add&summary&id_product='+productId+'&ipa='+productAttributeId + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token ,
data: 'ajax=true&add&getproductprice&summary&id_product='+productId+'&ipa='+productAttributeId + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token ,
success: function(jsonData)
{
if (jsonData.hasError)
@@ -206,7 +206,7 @@ function downQuantity(id, qty)
async: true,
cache: false,
dataType: 'json',
data: 'ajax=true&add&summary&id_product='+productId+'&ipa='+productAttributeId+'&op=down' + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token ,
data: 'ajax=true&add&getproductprice&summary&id_product='+productId+'&ipa='+productAttributeId+'&op=down' + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token ,
success: function(jsonData)
{
if (jsonData.hasError)
@@ -250,6 +250,21 @@ function updateCartSummary(json)
for (i=0;i<json.products.length;i++)
{
// if reduction, we need to show it in the cart by showing the initial price above the current one
var reduction = json.products[i].reduction_applies;
var initial_price_text = '';
initial_price = formatCurrency(json.products[i].price_without_quantity_discount, currencyFormat, currencySign, currencyBlank);
var current_price = '';
if (priceDisplayMethod != 0)
current_price = formatCurrency(json.products[i].price, currencyFormat, currencySign, currencyBlank);
else
current_price = formatCurrency(json.products[i].price_wt, currencyFormat, currencySign, currencyBlank);
if (reduction && typeof(initial_price) != 'undefined')
{
if (initial_price != '' && initial_price > current_price)
initial_price_text = '<span style="text-decoration:line-through;">'+initial_price+'</span><br />';
}
key_for_blockcart = json.products[i].id_product+'_'+json.products[i].id_product_attribute;
if (json.products[i].id_product_attribute == 0)
key_for_blockcart = json.products[i].id_product;
@@ -259,13 +274,13 @@ function updateCartSummary(json)
if (priceDisplayMethod != 0)
{
$('#cart_block_product_'+key_for_blockcart+' span.price').html(formatCurrency(json.products[i].total, currencyFormat, currencySign, currencyBlank));
$('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].price, currencyFormat, currencySign, currencyBlank));
$('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(initial_price_text+current_price);
$('#total_product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].total, currencyFormat, currencySign, currencyBlank));
}
else
{
$('#cart_block_product_'+key_for_blockcart+' span.price').html(formatCurrency(json.products[i].total_wt, currencyFormat, currencySign, currencyBlank));
$('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].price_wt, currencyFormat, currencySign, currencyBlank));
$('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(initial_price_text+current_price);
$('#total_product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].total_wt, currencyFormat, currencySign, currencyBlank));
}
@@ -286,6 +301,7 @@ function updateCartSummary(json)
$('#cart_quantity_down_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+(json.products[i].id_customization != null ? '_'+json.products[i].id_customization : '')).fadeTo('slow',0.3);
else
$('#cart_quantity_down_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+(json.products[i].id_customization != null ? '_'+json.products[i].id_customization : '')).fadeTo('slow',1);
}
// Update discounts
@@ -406,5 +422,4 @@ function updateHookShoppingCart(html)
function updateHookShoppingCartExtra(html)
{
$('#HOOK_SHOPPING_CART_EXTRA').html(html);
}
}
@@ -42,7 +42,17 @@
</td>
<td class="cart_unit">
<span class="price" id="product_price_{$product.id_product}_{$product.id_product_attribute}">
{if !$priceDisplay}{convertPrice price=$product.price_wt}{else}{convertPrice price=$product.price}{/if}
{if !$priceDisplay}
{if {convertPrice price=$product.price_without_specific_price} != {convertPrice price=$product.price_wt}}
<span style="text-decoration:line-through;">{convertPrice price=$product.price_without_specific_price}</span><br />
{/if}
{convertPrice price=$product.price_wt}
{else}
{if {convertPrice price=$product.price_without_specific_price} != {convertPrice price=$product.price}}
<span style="text-decoration:line-through;">{convertPrice price=$product.price_without_specific_price}</span><br />
{/if}
{convertPrice price=$product.price}
{/if}
</span>
</td>
<td class="cart_quantity"{if isset($customizedDatas.$productId.$productAttributeId) AND $quantityDisplayed == 0} style="text-align: center;"{/if}>