diff --git a/classes/Module.php b/classes/Module.php index b5d630f37..ca6b04d63 100644 --- a/classes/Module.php +++ b/classes/Module.php @@ -469,7 +469,7 @@ abstract class ModuleCore $this->unregisterExceptions($hookID, $shopList); $result &= $this->registerExceptions($hookID, $except, $shopList); } - + return $result; } @@ -572,9 +572,9 @@ abstract class ModuleCore $modulesNameToCursor = array(); $errors = array(); $modules_dir = self::getModulesDirOnDisk(); - + $memory_limit = Tools::getMemoryLimit(); - + foreach ($modules_dir AS $module) { // Memory usage checking @@ -589,7 +589,7 @@ abstract class ModuleCore break; } } - + $configFile = _PS_MODULE_DIR_.$module.'/config.xml'; $xml_exist = file_exists($configFile); if ($xml_exist) @@ -1154,6 +1154,24 @@ abstract class ModuleCore return $result; } + /** + * Assign a smarty vars (same syntax as smarty->assign) but prefix all keys with module name + * + * @since 1.5.0 + * @param string $key Variable key (can be an array) + * @param mixed $value Variable value + */ + public function smartyAssign($key, $value = null) + { + if (is_array($key)) + { + foreach ($key as $k => $v) + $this->context->smarty->assign($this->name.'_'.$k, $v); + } + else + $this->context->smarty->assign($this->name.'_'.$key, $value); + } + protected function _getApplicableTemplateDir($template) { return $this->_isTemplateOverloaded($template) ? _PS_THEME_DIR_ : _PS_MODULE_DIR_.$this->name.'/'; diff --git a/modules/blockcart/blockcart-json.tpl b/modules/blockcart/blockcart-json.tpl index 8f08a6f1f..8dcce7536 100644 --- a/modules/blockcart/blockcart-json.tpl +++ b/modules/blockcart/blockcart-json.tpl @@ -1,5 +1,5 @@ {* -* 2007-2011 PrestaShop +* 2007-2011 PrestaShop * * NOTICE OF LICENSE * @@ -26,8 +26,8 @@ {ldelim} "products": [ -{if $products} -{foreach from=$products item=product name='products'} +{if $blockcart_products} +{foreach from=$blockcart_products item=product name='products'} {assign var='productId' value=$product.id_product} {assign var='productAttributeId' value=$product.id_product_attribute} {ldelim} @@ -44,11 +44,11 @@ {else} "hasAttributes": false, {/if} - "hasCustomizedDatas": {if isset($customizedDatas.$productId.$productAttributeId)}true{else}false{/if}, + "hasCustomizedDatas": {if isset($blockcart_customizedDatas.$productId.$productAttributeId)}true{else}false{/if}, "customizedDatas":[ - {if isset($customizedDatas.$productId.$productAttributeId)} - {foreach from=$customizedDatas.$productId.$productAttributeId key='id_customization' item='customization' name='customizedDatas'}{ldelim} + {if isset($blockcart_customizedDatas.$productId.$productAttributeId)} + {foreach from=$blockcart_customizedDatas.$productId.$productAttributeId key='id_customization' item='customization' name='customizedDatas'}{ldelim} {* This empty line was made in purpose (product addition debug), please leave it here *} "customizationId": {$id_customization}, @@ -80,7 +80,7 @@ ], "discounts": [ -{if $discounts}{foreach from=$discounts item=discount name='discounts'} +{if $blockcart_discounts}{foreach from=$blockcart_discounts item=discount name='discounts'} {ldelim} "id": "{$discount.id_discount}", "name": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}", @@ -93,19 +93,19 @@ {/foreach}{/if} ], -"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}", -{if isset($tax_cost)} -"taxCost": "{$tax_cost|html_entity_decode:2:'UTF-8'}", +"shippingCost": "{$blockcart_shipping_cost|html_entity_decode:2:'UTF-8'}", +{if isset($blockcart_tax_cost)} +"taxCost": "{$blockcart_tax_cost|html_entity_decode:2:'UTF-8'}", {/if} -"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}", -"nbTotalProducts": "{$nb_total_products}", -"total": "{$total|html_entity_decode:2:'UTF-8'}", -"productTotal": "{$product_total|html_entity_decode:2:'UTF-8'}", +"wrappingCost": "{$blockcart_wrapping_cost|html_entity_decode:2:'UTF-8'}", +"nbTotalProducts": "{$blockcart_nb_total_products}", +"total": "{$blockcart_total|html_entity_decode:2:'UTF-8'}", +"productTotal": "{$blockcart_product_total|html_entity_decode:2:'UTF-8'}", -{if isset($errors) && $errors} +{if isset($blockcart_errors) && $blockcart_errors} "hasError" : true, "errors" : [ -{foreach from=$errors key=k item=error name='errors'} +{foreach from=$blockcart_errors key=k item=error name='errors'} "{$error|addslashes|html_entity_decode:2:'UTF-8'}" {if !$smarty.foreach.errors.last},{/if} {/foreach} diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php index 324bc0658..8a74ba74d 100644 --- a/modules/blockcart/blockcart.php +++ b/modules/blockcart/blockcart.php @@ -44,7 +44,7 @@ class BlockCart extends Module $this->description = $this->l('Adds a block containing the customer\'s shopping cart.'); } - public function smartyAssigns(&$smarty, &$params) + public function assignContentVars(&$params) { global $errors; @@ -77,10 +77,10 @@ class BlockCart extends Module if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1) { $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); - $smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); + $this->smartyAssign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); } - $smarty->assign(array( + $this->smartyAssign(array( 'products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, @@ -98,9 +98,9 @@ class BlockCart extends Module 'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false )); if (sizeof($errors)) - $smarty->assign('errors', $errors); + $this->smartyAssign('errors', $errors); if(isset($this->context->cookie->ajax_blockcart_display)) - $smarty->assign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); + $this->smartyAssign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); } public function getContent() @@ -159,8 +159,9 @@ class BlockCart extends Module if (Configuration::get('PS_CATALOG_MODE')) return; - $this->context->smarty->assign('order_page', strpos($_SERVER['PHP_SELF'], 'order') !== false); - $this->smartyAssigns($this->context->smarty, $params); + // @todo this variable seems not used + $this->smartyAssign('order_page', strpos($_SERVER['PHP_SELF'], 'order') !== false); + $this->assignContentVars($params); return $this->display(__FILE__, 'blockcart.tpl'); } @@ -174,7 +175,7 @@ class BlockCart extends Module if (Configuration::get('PS_CATALOG_MODE')) return; - $this->smartyAssigns($this->context->smarty, $params); + $this->assignContentVars($params); $res = $this->display(__FILE__, 'blockcart-json.tpl'); return $res; } diff --git a/modules/blockcart/blockcart.tpl b/modules/blockcart/blockcart.tpl index cf8fe211c..cde0abeca 100644 --- a/modules/blockcart/blockcart.tpl +++ b/modules/blockcart/blockcart.tpl @@ -27,9 +27,9 @@ {*************************************************************************************************************************************} {* IMPORTANT : If you change some data here, you have to report these changes in the ./blockcart-json.js (to let ajaxCart available) *} {*************************************************************************************************************************************} -{if $ajax_allowed} +{if $blockcart_ajax_allowed} @@ -38,15 +38,15 @@ var removingLinkText = '{l s='remove this product from my cart' mod='blockcart'