[-] FO : ajax cart now display cart rules correctly #PSTEST-724

// Small addition to the controller override

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13527 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dMetzger
2012-02-22 11:02:49 +00:00
parent 41ef496d74
commit 7e73e088e5
8 changed files with 80 additions and 13 deletions
+5
View File
@@ -307,6 +307,11 @@ abstract class CacheCore
return isset(Cache::$local[$key]) ? Cache::$local[$key] : null;
}
public static function retrieveAll()
{
return Cache::$local;
}
public static function isStored($key)
{
return isset(Cache::$local[$key]);
+14 -6
View File
@@ -375,7 +375,7 @@ var ajaxCart = {
var toDelete = true;
for (i=0;i<jsonData.discounts.length;i++)
{
if (jsonData.discounts[i].id == idElmt)
if (jsonData.discounts[i].id == idElmt && parseFloat(jsonData.discounts[i].price_float) > 0)
{
$('#bloc_cart_voucher_' + idElmt + ' td.price').text(jsonData.discounts[i].price);
toDelete = false;
@@ -429,7 +429,7 @@ var ajaxCart = {
var domIdProduct = this.id + '_' + (this.idCombination ? this.idCombination : '0') + '_' + (this.idAddressDelivery ? this.idAddressDelivery : '0');
var domIdProductAttribute = this.id + '_' + (this.idCombination ? this.idCombination : '0');
if($('#cart_block dt#cart_block_product_'+ domIdProduct ).length == 0)
if ($('#cart_block dt#cart_block_product_'+ domIdProduct ).length == 0)
{
var productId = parseInt(this.id);
var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0);
@@ -438,7 +438,7 @@ var ajaxCart = {
var name = (this.name.length > 12 ? this.name.substring(0, 10) + '...' : this.name);
content += '<a href="' + this.link + '" title="' + this.name + '">' + name + '</a>';
content += '<span class="remove_link"><a rel="nofollow" class="ajax_cart_block_remove_link" href="' + baseDir + 'index.php?controller=cart&amp;delete&amp;id_product=' + productId + '&amp;token=' + static_token + (this.hasAttributes ? '&amp;ipa=' + parseInt(this.idCombination) : '') + '"> </a></span>';
content += '<span class="price">' + this.priceByLine + '</span>';
content += '<span class="price">' + (parseFloat(this.price_float) > 0 ? this.priceByLine : freeProductTranslation) + '</span>';
content += '</dt>';
if (this.hasAttributes)
content += '<dd id="cart_block_combination_of_' + domIdProduct + '" class="hidden"><a href="' + this.link + '" title="' + this.name + '">' + this.attributes + '</a>';
@@ -449,12 +449,16 @@ var ajaxCart = {
$('#cart_block dl.products').append(content);
}
//else update the product's line
else{
else
{
var jsonProduct = this;
if($('dt#cart_block_product_' + domIdProduct + ' .quantity').text() != jsonProduct.quantity || $('dt#cart_block_product_' + domIdProduct + ' .price').text() != jsonProduct.priceByLine)
{
// Usual product
$('dt#cart_block_product_' + domIdProduct + ' .price').text(jsonProduct.priceByLine);
if (parseFloat(this.price_float) > 0)
$('dt#cart_block_product_' + domIdProduct + ' .price').text(jsonProduct.priceByLine);
else
$('dt#cart_block_product_' + domIdProduct + ' .price').html(freeProductTranslation);
ajaxCart.updateProductQuantity(jsonProduct, jsonProduct.quantity);
// Customized product
@@ -577,7 +581,11 @@ var ajaxCart = {
//update general cart informations everywhere in the page
updateCartEverywhere : function(jsonData) {
$('.ajax_cart_total').text(jsonData.productTotal);
$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);
if (parseFloat(jsonData.shippingCostFloat) > 0)
$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);
else
$('.ajax_cart_shipping_cost').html(freeShippingTranslation);
$('.ajax_cart_tax_cost').text(jsonData.taxCost);
$('.cart_block_wrapping_cost').text(jsonData.wrappingCost);
$('.ajax_block_cart_total').text(jsonData.total);
+4 -1
View File
@@ -37,6 +37,7 @@
"priceByLine": "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
"name": "{$product.name|html_entity_decode:2:'UTF-8'|escape|truncate:15:'...':true}",
"price": "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
"price_float": "{$product.total}",
"idCombination": {if isset($product.attributes_small)}{$productAttributeId}{else}0{/if},
"idAddressDelivery": {if isset($product.id_address_delivery)}{$product.id_address_delivery}{else}0{/if},
{if isset($product.attributes_small)}
@@ -88,13 +89,15 @@
"description": "{$discount.description|addslashes|replace:'\\\'':'\''}",
"nameDescription": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
"link": "{$link->getPageLink('order', true, NULL, "deleteDiscount={$discount.id_discount}")}",
"price": "-{if $discount.value_real != '!'}{if $priceDisplay == 1}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_tax_exc}{else}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_real}{/if}{/if}"
"price": "{if $priceDisplay == 1}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_tax_exc}{else}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_real}{/if}",
"price_float": "{if $priceDisplay == 1}{$discount.value_tax_exc}{else}{$discount.value_real}{/if}"
{rdelim}
{if !$smarty.foreach.discounts.last},{/if}
{/foreach}{/if}
],
"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}",
"shippingCostFloat": "{$shipping_cost_float|html_entity_decode:2:'UTF-8'}",
{if isset($tax_cost)}
"taxCost": "{$tax_cost|html_entity_decode:2:'UTF-8'}",
{/if}
+8
View File
@@ -101,3 +101,11 @@
#cart_block table#vouchers tr td{
padding: 2px;
}
#cart_block table#vouchers tr td.quantity{
margin-right:5px;
min-width:18px
}
#cart_block table#vouchers tr td.delete{
text-align: right;
}
+27 -2
View File
@@ -70,7 +70,10 @@ class BlockCart extends Module
$nbTotalProducts = 0;
foreach ($products as $product)
$nbTotalProducts += (int)$product['cart_quantity'];
$cart_rules = $params['cart']->getCartRules();
$shipping_cost = Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING), $currency);
$shipping_cost_float = Tools::convertPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING), $currency);
$wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING));
$totalToPay = $params['cart']->getOrderTotal($useTax);
@@ -79,15 +82,37 @@ class BlockCart extends Module
$totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
$this->smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency));
}
foreach ($cart_rules as &$cart_rule)
{
if ($cart_rule['free_shipping'])
{
$shipping_cost = Tools::displayPrice(0, $currency);
$shipping_cost_float = 0;
$cart_rule['value_real'] -= Tools::convertPrice($params['cart']->getOrderTotal(true, Cart::ONLY_SHIPPING), $currency);
$cart_rule['value_tax_exc'] = Tools::convertPrice($params['cart']->getOrderTotal(false, Cart::ONLY_SHIPPING), $currency);
}
elseif ($cart_rule['gift_product'])
{
foreach ($products as &$product)
if ($product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute'])
{
$product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$product['total'] = Tools::ps_round($product['total'] - $product['price'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
$cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
}
}
}
$this->smarty->assign(array(
'products' => $products,
'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)),
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
'discounts' => $params['cart']->getCartRules(),
'discounts' => $cart_rules,
'nb_total_products' => (int)($nbTotalProducts),
'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING), $currency),
'shipping_cost' => $shipping_cost,
'shipping_cost_float' => $shipping_cost_float,
'show_wrapping' => $wrappingCost > 0 ? true : false,
'show_tax' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')),
'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency),
+13 -2
View File
@@ -32,6 +32,8 @@
var CUSTOMIZE_TEXTFIELD = {$CUSTOMIZE_TEXTFIELD};
var customizationIdMessage = '{l s='Customization #' mod='blockcart' js=1}';
var removingLinkText = '{l s='remove this product from my cart' mod='blockcart' js=1}';
var freeShippingTranslation = '<b>{l s='Free shipping!' mod='blockcart' js=1}</b>';
var freeProductTranslation = '<b>{l s='Free!' mod='blockcart' js=1}</b>';
</script>
{/if}
@@ -65,7 +67,13 @@ var removingLinkText = '{l s='remove this product from my cart' mod='blockcart'
<a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)}" title="{$product.name|escape:html:'UTF-8'}">
{$product.name|truncate:13:'...'|escape:html:'UTF-8'}</a>
<span class="remove_link">{if !isset($customizedDatas.$productId.$productAttributeId)}<a rel="nofollow" class="ajax_cart_block_remove_link" href="{$link->getPageLink('cart', true, NULL, "delete&amp;id_product={$product.id_product}&amp;ipa={$product.id_product_attribute}&amp;id_address_delivery={$product.id_address_delivery}&amp;token={$static_token}")}" title="{l s='remove this product from my cart' mod='blockcart'}">&nbsp;</a>{/if}</span>
<span class="price">{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$product.total`"}{else}{displayWtPrice p="`$product.total_wt`"}{/if}</span>
<span class="price">{$product.total}
{if $product.total > 0}
{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$product.total`"}{else}{displayWtPrice p="`$product.total_wt`"}{/if}
{else}
<b>{l s='Free!' mod='blockcart'}</b>
{/if}
</span>
</dt>
{if isset($product.attributes_small)}
<dd id="cart_block_combination_of_{$product.id_product}{if $product.id_product_attribute}_{$product.id_product_attribute}{/if}_{$product.id_address_delivery|intval}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">
@@ -100,11 +108,14 @@ var removingLinkText = '{l s='remove this product from my cart' mod='blockcart'
{if $discounts|@count > 0}<table id="vouchers">
<tbody>
{foreach from=$discounts item=discount}
{if $discount.value_real > 0}
<tr class="bloc_cart_voucher" id="bloc_cart_voucher_{$discount.id_discount}">
<td class="quantity">1x</td>
<td class="name" title="{$discount.description}">{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|escape:'htmlall':'UTF-8'}</td>
<td class="price">-{if $discount.value_real != '!'}{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}{/if}</td>
<td class="price">-{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}</td>
<td class="delete"><a href="{$link->getPageLink('$order_process.php', true)}?deleteDiscount={$discount.id_discount}" title="{l s='Delete'}"><img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="icon" /></a></td>
</tr>
{/if}
{/foreach}
</tbody>
</table>
+2
View File
@@ -15,6 +15,8 @@ $_MODULE['<{blockcart}prestashop>blockcart_dba281afb9a38e654ea9dab4cd6cb0ca'] =
$_MODULE['<{blockcart}prestashop>blockcart_c9cc8cce247e49bae79f15173ce97354'] = 'Enregistrer';
$_MODULE['<{blockcart}prestashop>blockcart_20351b3328c35ab617549920f5cb4939'] = 'Personnalisation ';
$_MODULE['<{blockcart}prestashop>blockcart_ed6e9a09a111035684bb23682561e12d'] = 'supprimer cet article du panier';
$_MODULE['<{blockcart}prestashop>blockcart_c6995d6cc084c192bc2e742f052a5c74'] = 'Offert !';
$_MODULE['<{blockcart}prestashop>blockcart_e7a6ca4e744870d455a57b644f696457'] = 'Offert !';
$_MODULE['<{blockcart}prestashop>blockcart_a85eba4c6c699122b2bb1387ea4813ad'] = 'Panier';
$_MODULE['<{blockcart}prestashop>blockcart_86024cad1e83101d97359d7351051156'] = 'articles';
$_MODULE['<{blockcart}prestashop>blockcart_f5bf48aa40cad7891eb709fcf1fde128'] = 'article';
+7 -2
View File
@@ -304,6 +304,9 @@ abstract class Controller extends ControllerCore
$globalSize[$key] = round($size / 1024, 1);
}
arsort($globalSize);
$cache = Cache::retrieveAll();
$totalCacheSize = $this->sizeofvar($cache);
echo '<br /><br />
<div class="rte" style="text-align:left;padding:8px;float:left">
@@ -326,7 +329,7 @@ abstract class Controller extends ControllerCore
echo '</ul>
</div>
<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">
<b>Memory peak usage</b>: '.$this->displayMemoryColor(memory_get_peak_usage()).'';
<b>Memory peak usage</b>: '.$this->displayMemoryColor(memory_get_peak_usage());
if (self::$_footer)
{
echo '<ul>';
@@ -338,7 +341,9 @@ abstract class Controller extends ControllerCore
}
echo '</ul>';
}
echo '</div>';
echo '<br /><br />
<b>Total cache size (in Cache class)</b>: '.$this->displayMemoryColor($totalCacheSize).'
</div>';
echo '
<div class="rte" style="text-align:left;padding:8px;float:left;margin-left:20px">