From 875d5488e69d117c15984697eb670f71e806707a Mon Sep 17 00:00:00 2001 From: vChabot Date: Thu, 15 Sep 2011 12:37:44 +0000 Subject: [PATCH] [*] FO : display initial price in the cart when a specific price is applied to a product --- cache/class_index.php | 2 +- classes/Cart.php | 3 ++- controllers/CartController.php | 4 +++ controllers/ParentOrderController.php | 9 ++++--- themes/prestashop/js/cart-summary.js | 27 ++++++++++++++----- .../prestashop/shopping-cart-product-line.tpl | 12 ++++++++- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/cache/class_index.php b/cache/class_index.php index 0fc7b0b3e..60f81638b 100644 --- a/cache/class_index.php +++ b/cache/class_index.php @@ -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', diff --git a/classes/Cart.php b/classes/Cart.php index eb4547b5d..5e1cbee32 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -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; diff --git a/controllers/CartController.php b/controllers/CartController.php index 95be60735..b259025fc 100644 --- a/controllers/CartController.php +++ b/controllers/CartController.php @@ -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 diff --git a/controllers/ParentOrderController.php b/controllers/ParentOrderController.php index 53de1e1e4..1f6a820ed 100644 --- a/controllers/ParentOrderController.php +++ b/controllers/ParentOrderController.php @@ -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( diff --git a/themes/prestashop/js/cart-summary.js b/themes/prestashop/js/cart-summary.js index f62eea96d..45f213e02 100644 --- a/themes/prestashop/js/cart-summary.js +++ b/themes/prestashop/js/cart-summary.js @@ -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 current_price) + initial_price_text = ''+initial_price+'
'; + } + 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); -} - +} \ No newline at end of file diff --git a/themes/prestashop/shopping-cart-product-line.tpl b/themes/prestashop/shopping-cart-product-line.tpl index 4237feddc..f4036eaae 100644 --- a/themes/prestashop/shopping-cart-product-line.tpl +++ b/themes/prestashop/shopping-cart-product-line.tpl @@ -42,7 +42,17 @@ - {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}} + {convertPrice price=$product.price_without_specific_price}
+ {/if} + {convertPrice price=$product.price_wt} + {else} + {if {convertPrice price=$product.price_without_specific_price} != {convertPrice price=$product.price}} + {convertPrice price=$product.price_without_specific_price}
+ {/if} + {convertPrice price=$product.price} + {/if}