From dc957d3d3a5aeeac32f73b6a639ec2902eb8615f Mon Sep 17 00:00:00 2001 From: rMalie Date: Fri, 23 Sep 2011 13:50:33 +0000 Subject: [PATCH] // Rename Module->smartyAssign to Module->templateAssign [+] Front: Add module controller + url dispatch for modules --- admin-dev/tabs/AdminMeta.php | 29 ++++---- cache/class_index.php | 2 + classes/Dispatcher.php | 8 +++ classes/FrontController.php | 2 +- classes/Link.php | 66 +++++++++++------ classes/Module.php | 19 ++++- init.php | 11 ++- install-dev/classes/Module.php | 72 +++++++++---------- modules/blockcart/blockcart.php | 10 +-- modules/blockcms/blockcms.php | 4 +- modules/blocklanguages/blocklanguages.php | 2 +- .../blockmanufacturer/blockmanufacturer.php | 3 +- modules/blockmyaccount/blockmyaccount.php | 2 +- modules/blocknewproducts/blocknewproducts.php | 2 +- modules/blockspecials/blockspecials.php | 2 +- modules/blockuserinfo/blockuserinfo.php | 2 +- modules/blockviewed/blockviewed.php | 2 +- modules/cheque/cheque.php | 59 ++++++++------- modules/cheque/payment.tpl | 4 +- modules/homefeatured/homefeatured.php | 2 +- .../controllers/front/ModuleController.php | 7 ++ 21 files changed, 190 insertions(+), 120 deletions(-) create mode 100644 override/controllers/front/ModuleController.php diff --git a/admin-dev/tabs/AdminMeta.php b/admin-dev/tabs/AdminMeta.php index e023a89fd..ebcfe93c9 100644 --- a/admin-dev/tabs/AdminMeta.php +++ b/admin-dev/tabs/AdminMeta.php @@ -1,6 +1,6 @@ array(), ), ); - + // Display route options only if friendly URL is activated if (Configuration::get('PS_REWRITING_SETTINGS')) { @@ -69,9 +69,10 @@ class AdminMeta extends AdminTab $this->addFieldRoute('manufacturer_rule', $this->l('Route to manufacturer')); $this->addFieldRoute('cms_rule', $this->l('Route to CMS page')); $this->addFieldRoute('cms_category_rule', $this->l('Route to CMS category')); + $this->addFieldRoute('module', $this->l('Route to modules')); } } - + public function addFieldRoute($routeID, $title) { $keywords = array(); @@ -91,7 +92,7 @@ class AdminMeta extends AdminTab public function displayForm($isMainTab = true) { parent::displayForm(); - + if (!($meta = $this->loadObject(true))) return; $files = Meta::getPages(true, ($meta->page ? $meta->page : false)); @@ -174,7 +175,7 @@ class AdminMeta extends AdminTab '; } - + public function postProcess() { if (Tools::isSubmit('submitAddmeta')) @@ -210,18 +211,18 @@ class AdminMeta extends AdminTab } Module::hookExec('afterSaveAdminMeta'); } - + return parent::postProcess(); } - + public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false) { parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID(true)); } - + /** * Validate route syntax and save it in configuration - * + * * @param string $routeID */ public function checkAndUpdateRoute($routeID) @@ -229,7 +230,7 @@ class AdminMeta extends AdminTab $default_routes = Dispatcher::getInstance()->default_routes; if (!isset($default_routes[$routeID])) return ; - + $rule = Tools::getValue('PS_ROUTE_'.$routeID); if (!$rule || $rule == $default_routes[$routeID]['rule']) { @@ -256,22 +257,22 @@ class AdminMeta extends AdminTab { $this->checkAndUpdateRoute('category_rule'); } - + public function updateOptionPsRouteSupplierRule() { $this->checkAndUpdateRoute('supplier_rule'); } - + public function updateOptionPsRouteManufacturerRule() { $this->checkAndUpdateRoute('manufacturer_rule'); } - + public function updateOptionPsRouteCmsRule() { $this->checkAndUpdateRoute('cms_rule'); } - + public function updateOptionPsRouteCmsCategoryRule() { $this->checkAndUpdateRoute('cms_category_rule'); diff --git a/cache/class_index.php b/cache/class_index.php index 0209b0bf1..25c386e9a 100644 --- a/cache/class_index.php +++ b/cache/class_index.php @@ -315,6 +315,8 @@ 'IndexController' => 'override/controllers/front/IndexController.php', 'ManufacturerControllerCore' => 'controllers/front/ManufacturerController.php', 'ManufacturerController' => 'override/controllers/front/ManufacturerController.php', + 'ModuleControllerCore' => 'controllers/front/ModuleController.php', + 'ModuleController' => 'override/controllers/front/ModuleController.php', 'MyAccountControllerCore' => 'controllers/front/MyAccountController.php', 'MyAccountController' => 'override/controllers/front/MyAccountController.php', 'NewProductsControllerCore' => 'controllers/front/NewProductsController.php', diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index b7fe97ffc..17d44f78a 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -108,6 +108,14 @@ class DispatcherCore 'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'), ), ), + 'module' => array( + 'controller' => 'module', + 'rule' => 'module/{name}/{action}', + 'keywords' => array( + 'name' => array('regexp' => '[a-zA-Z0-9_-]+', 'param' => 'module'), + 'action' => array('regexp' => '[a-zA-Z0-9_-]+', 'param' => 'action'), + ), + ), ); /** diff --git a/classes/FrontController.php b/classes/FrontController.php index ca491b509..10968697c 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -25,7 +25,7 @@ * International Registered Trademark & Property of PrestaShop SA */ -class FrontControllerCore extends ControllerCore +class FrontControllerCore extends Controller { public $errors = array(); diff --git a/classes/Link.php b/classes/Link.php index 9e60b5d91..a60edf164 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -1,6 +1,6 @@ array()); - + public $protocol_link; public $protocol_content; @@ -74,7 +74,7 @@ class LinkCore { $dispatcher = Dispatcher::getInstance(); $url = _PS_BASE_URL_.__PS_BASE_URI__; - + if (!$id_lang) $id_lang = Context::getContext()->language->id; @@ -97,10 +97,10 @@ class LinkCore if ($dispatcher->hasKeyword('product_rule', 'manufacturer')) $params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer)); - + if ($dispatcher->hasKeyword('product_rule', 'supplier')) $params['supplier'] = Tools::str2url($product->isFullyLoaded ? $product->supplier_name : Supplier::getNameById($product->id_supplier)); - + if ($dispatcher->hasKeyword('product_rule', 'price')) $params['supplier'] = $product->isFullyLoaded ? $product->price : Product::getPriceStatic($product->id, false, NULL, 6, NULL, false, true, 1, false, NULL, NULL, NULL, $product->specificPrice); @@ -118,7 +118,7 @@ class LinkCore * @param int $id_lang * @return string */ - public function getCategoryLink($category, $alias = NULL, $id_lang = NULL) + public function getCategoryLink($category, $alias = null, $id_lang = null) { $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!$id_lang) @@ -145,7 +145,7 @@ class LinkCore * @param int $id_lang * @return string */ - public function getCMSCategoryLink($category, $alias = NULL, $id_lang = NULL) + public function getCMSCategoryLink($category, $alias = null, $id_lang = null) { $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!$id_lang) @@ -173,7 +173,7 @@ class LinkCore * @param int $id_lang * @return string */ - public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = NULL) + public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null) { $base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true)); $url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang); @@ -201,7 +201,7 @@ class LinkCore * @param int $id_lang * @return string */ - public function getSupplierLink($supplier, $alias = NULL, $id_lang = NULL) + public function getSupplierLink($supplier, $alias = null, $id_lang = null) { $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!$id_lang) @@ -228,7 +228,7 @@ class LinkCore * @param int $id_lang * @return string */ - public function getManufacturerLink($manufacturer, $alias = NULL, $id_lang = NULL) + public function getManufacturerLink($manufacturer, $alias = null, $id_lang = null) { $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!$id_lang) @@ -247,18 +247,42 @@ class LinkCore return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $params, $this->allow); } + /** + * Create a link to a supplier + * + * @since 1.5.0 + * @param string $name Module name + * @param string $action Action name + * @param int $id_lang + * @return string + */ + public function getModuleLink($name, $action, $ssl = false, $id_lang = null) + { + $base = (($ssl && Configuration::get('PS_SSL_ENABLED')) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); + $url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang); + if (!$id_lang) + $id_lang = Context::getContext()->language->id; + + // Set available keywords + $params = array(); + $params['name'] = $name; + $params['action'] = $action; + + return $url.Dispatcher::getInstance()->createUrl('module', $params, $this->allow); + } + /** * Returns a link to a product image for display * Note: the new image filesystem stores product images in subdirectories of img/p/ - * + * * @param string $name rewrite link of the image * @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new) * @param string $type */ - public function getImageLink($name, $ids, $type = NULL) + public function getImageLink($name, $ids, $type = null) { // legacy mode or default image - if ((Configuration::get('PS_LEGACY_IMAGES') + if ((Configuration::get('PS_LEGACY_IMAGES') && (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'.jpg'))) || strpos($ids, 'default') !== false) { @@ -271,13 +295,13 @@ class LinkCore // if ids if of the form id_product-id_image, we want to extract the id_image part $split_ids = explode('-', $ids); $id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]); - + if ($this->allow == 1) $uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').'/'.$name.'.jpg'; else $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'.jpg'; } - + return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path; } @@ -288,7 +312,7 @@ class LinkCore /** * Create a simple link - * + * * @param string $controller * @param bool $ssl * @param int $id_lang @@ -344,7 +368,7 @@ class LinkCore parse_str($_SERVER['QUERY_STRING'], $queryTab); unset($queryTab['isolang'], $queryTab['controller']); - + if (!$this->allow) $queryTab['id_lang'] = $id_lang; @@ -377,11 +401,11 @@ class LinkCore { if (Configuration::get('PS_REWRITING_SETTINGS') AND ($k == 'isolang' OR $k == 'id_lang')) continue; - $ifNb = (!$nb OR ($nb AND !in_array($k, $varsNb))); + $ifNb = (!$nb || ($nb AND !in_array($k, $varsNb))); $ifSort = (!$sort OR ($sort AND !in_array($k, $varsSort))); - $ifPagination = (!$pagination OR ($pagination AND !in_array($k, $varsPagination))); - if ($ifNb AND $ifSort AND $ifPagination AND !is_array($value)) - !$array ? ($vars .= ((!$n++ AND ($this->allow == 1 OR $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value)); + $ifPagination = (!$pagination || ($pagination && !in_array($k, $varsPagination))); + if ($ifNb && $ifSort && $ifPagination AND !is_array($value)) + !$array ? ($vars .= ((!$n++ && ($this->allow == 1 || $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value)); } if (!$array) return $url.$vars; diff --git a/classes/Module.php b/classes/Module.php index 235c6cfe3..8e91eb1b6 100644 --- a/classes/Module.php +++ b/classes/Module.php @@ -515,7 +515,7 @@ abstract class ModuleCore * Return an instance of the specified module * * @param string $moduleName Module name - * @return Module instance + * @return Module */ public static function getInstanceByName($moduleName) { @@ -1158,6 +1158,21 @@ abstract class ModuleCore return $result; } + /** + * Get realpath of a template of current module (check if template is overriden too) + * + * @since 1.5.0 + * @param string $template + * @return string + */ + public function getTemplatePath($template) + { + $overloaded = $this->_isTemplateOverloaded($template); + if (is_null($overloaded)) + return null; + return ($overloaded ? _PS_THEME_DIR_.'modules/'.$this->name : _PS_MODULE_DIR_.$this->name).'/'.$template; + } + /** * Assign a smarty vars (same syntax as smarty->assign) but prefix all keys with module name * @@ -1165,7 +1180,7 @@ abstract class ModuleCore * @param string $key Variable key (can be an array) * @param mixed $value Variable value */ - public function smartyAssign($key, $value = null) + public function templateAssign($key, $value = null) { if (is_array($key)) { diff --git a/init.php b/init.php index 52ec3a486..f5aa7ccdb 100644 --- a/init.php +++ b/init.php @@ -1,6 +1,6 @@ init(); \ No newline at end of file +if (isset(Context::getContext()->controller)) + $controller = Context::getContext()->controller; +else +{ + $controller = new FrontController(); + $controller->init(); +} \ No newline at end of file diff --git a/install-dev/classes/Module.php b/install-dev/classes/Module.php index c2cc5bba2..dae4d5589 100644 --- a/install-dev/classes/Module.php +++ b/install-dev/classes/Module.php @@ -44,7 +44,7 @@ abstract class Module /** @var string author of the module */ public $author; - + /** @var int need_instance */ public $need_instance = 1; @@ -84,11 +84,11 @@ abstract class Module */ protected static $modulesCache; protected static $_hookModulesCache; - + protected static $_INSTANCE = array(); - + protected static $_generateConfigXmlMode = false; - + protected static $l_cache = array(); /** @@ -168,14 +168,14 @@ abstract class Module } /** - * This function enable module $name. If an $name is an array, + * This function enable module $name. If an $name is an array, * this will enable all of them - * - * @param array|string $name + * + * @param array|string $name * @return true if succeed * @since 1.4.1 */ - public static function enableByName($name) + public static function enableByName($name) { if (!is_array($name)) $name = array($name); @@ -198,16 +198,16 @@ abstract class Module SET `active`= 1 WHERE `name` = \''.pSQL($this->name).'\''); } - + /** - * This function disable module $name. If an $name is an array, + * This function disable module $name. If an $name is an array, * this will disable all of them - * - * @param array|string $name + * + * @param array|string $name * @return true if succeed * @since 1.4.1 */ - public static function disableByName($name) + public static function disableByName($name) { if (!is_array($name)) $name = array($name); @@ -220,11 +220,11 @@ abstract class Module SET `active`= 0 WHERE `name` IN ('.implode(',',$name).')'); } - + /** * Called when module is set to deactive */ - public function disable() + public function disable() { return Module::disableByName($this->name); } @@ -369,11 +369,11 @@ abstract class Module /** - * This function is used to determine the module name + * This function is used to determine the module name * of an AdminTab which belongs to a module, in order to keep translation * related to a module in its directory (instead of $_LANGADM) - * - * @param mixed $currentClass the + * + * @param mixed $currentClass the * @return boolean|string if the class belongs to a module, will return the module name. Otherwise, return false. */ public static function getModuleNameFromClass($currentClass) @@ -396,7 +396,7 @@ abstract class Module if (Tools::file_exists_cache($file) AND include_once($file)) $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; } - else + else self::$classInModule[$currentClass] = false; } // return name of the module, or false @@ -434,7 +434,7 @@ abstract class Module if(!isset($preloadedModuleNameFromId)) { $preloadedModuleNameFromId = array(); } - + if(is_array($ids)) { foreach($ids as $id) @@ -458,12 +458,12 @@ abstract class Module else $preloadedModuleNameFromId[$ids] = false; } - + if(is_array($ids)) { return $preloadedModuleNameFromId; } else { - if(!isset($preloadedModuleNameFromId[$ids])) + if(!isset($preloadedModuleNameFromId[$ids])) return false; return $preloadedModuleNameFromId[$ids]; } @@ -674,7 +674,7 @@ abstract class Module AND m.`active` = 1 ORDER BY hm.`position`', false); self::$_hookModulesCache = array(); - + if ($result) while ($row = $db->nextRow()) { @@ -711,7 +711,7 @@ abstract class Module { $live_edit = true; $output .= ' -
' .$moduleInstance->displayName.' @@ -760,7 +760,7 @@ abstract class Module /** * find translation from $_MODULES and put it in self::$l_cache if not already exist * and return it. - * + * * @param string $name name of the module * @param string $string term to find * @param string $source additional param for building translation key @@ -769,9 +769,9 @@ abstract class Module public static function findTranslation($name, $string, $source) { global $_MODULES; - + $cache_key = $name . '|' . $string . '|' . $source; - + if (!isset(self::$l_cache[$cache_key])) { if (!is_array($_MODULES)) @@ -780,7 +780,7 @@ abstract class Module $_MODULES = array_change_key_case($_MODULES); $currentKey = '<{'.strtolower($name).'}'.strtolower(_THEME_NAME_).'>'.strtolower($source).'_'.md5($string); $defaultKey = '<{'.strtolower($name).'}prestashop>'.strtolower($source).'_'.md5($string); - + if (isset($_MODULES[$currentKey])) $ret = stripslashes($_MODULES[$currentKey]); elseif (isset($_MODULES[Tools::strtolower($currentKey)])) @@ -791,16 +791,16 @@ abstract class Module $ret = stripslashes($_MODULES[Tools::strtolower($defaultKey)]); else $ret = stripslashes($string); - + self::$l_cache[$cache_key] = str_replace('"', '"', $ret); - } + } return self::$l_cache[$cache_key]; } /** * Get translation for a given module text * * Note: $specific parameter is mandatory for library files. - * Otherwise, translation key will not match for Module library + * Otherwise, translation key will not match for Module library * when module is loaded with eval() Module::getModulesOnDisk() * * @param string $string String to translate @@ -811,14 +811,14 @@ abstract class Module { if (self::$_generateConfigXmlMode) return $string; - + global $_MODULES, $_MODULE, $cookie; $id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang); $file = _PS_MODULE_DIR_.$this->name.'/'.Language::getIsoById($id_lang).'.php'; if (Tools::file_exists_cache($file) AND include_once($file)) $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; - + $source = $specific ? $specific : $this->name; $string = str_replace('\'', '\\\'', $string); $ret = $this->findTranslation($this->name, $string, $source); @@ -897,7 +897,7 @@ abstract class Module */ public function getPosition($id_hook) { - if(isset(Hook::$preloadModulesFromHooks)) + if(isset(Hook::$preloadModulesFromHooks)) if(isset(Hook::$preloadModulesFromHooks[$id_hook])) if(isset(Hook::$preloadModulesFromHooks[$id_hook]['module_position'][$this->id])) return Hook::$preloadModulesFromHooks[$id_hook]['module_position'][$this->id]; @@ -1027,7 +1027,7 @@ abstract class Module return $smarty->clearCache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId); } - + protected function _generateConfigXml() { $xml = ' @@ -1044,7 +1044,7 @@ abstract class Module if (is_writable(_PS_MODULE_DIR_.$this->name.'/')) file_put_contents(_PS_MODULE_DIR_.$this->name.'/config.xml', utf8_encode($xml)); } - + /** * @param string $hook_name * @return bool if module can be transplanted on hook diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php index 8a74ba74d..5769324fa 100644 --- a/modules/blockcart/blockcart.php +++ b/modules/blockcart/blockcart.php @@ -77,10 +77,10 @@ class BlockCart extends Module if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1) { $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); - $this->smartyAssign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); + $this->templateAssign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); } - $this->smartyAssign(array( + $this->templateAssign(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)) - $this->smartyAssign('errors', $errors); + $this->templateAssign('errors', $errors); if(isset($this->context->cookie->ajax_blockcart_display)) - $this->smartyAssign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); + $this->templateAssign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); } public function getContent() @@ -160,7 +160,7 @@ class BlockCart extends Module return; // @todo this variable seems not used - $this->smartyAssign('order_page', strpos($_SERVER['PHP_SELF'], 'order') !== false); + $this->templateAssign('order_page', strpos($_SERVER['PHP_SELF'], 'order') !== false); $this->assignContentVars($params); return $this->display(__FILE__, 'blockcart.tpl'); } diff --git a/modules/blockcms/blockcms.php b/modules/blockcms/blockcms.php index d38253bf0..1fd840bf5 100755 --- a/modules/blockcms/blockcms.php +++ b/modules/blockcms/blockcms.php @@ -773,7 +773,7 @@ class BlockCms extends Module public function displayBlockCMS($column) { $cms_titles = self::getCMStitles($column); - $this->smartyAssign(array( + $this->templateAssign(array( 'block' => 1, 'cms_titles' => $cms_titles, )); @@ -796,7 +796,7 @@ class BlockCms extends Module if (Configuration::get('FOOTER_BLOCK_ACTIVATION')) { $cms_titles = self::getCMStitlesFooter(); - $this->smartyAssign(array( + $this->templateAssign(array( 'block' => 0, 'cmslinks' => $cms_titles, 'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'), diff --git a/modules/blocklanguages/blocklanguages.php b/modules/blocklanguages/blocklanguages.php index cf0e3e888..371d5cf08 100644 --- a/modules/blocklanguages/blocklanguages.php +++ b/modules/blocklanguages/blocklanguages.php @@ -92,7 +92,7 @@ class BlockLanguages extends Module } } if (count($default_rewrite)) - $this->smartyAssign('lang_rewrite_urls', $default_rewrite); + $this->templateAssign('lang_rewrite_urls', $default_rewrite); } return $this->display(__FILE__, 'blocklanguages.tpl'); diff --git a/modules/blockmanufacturer/blockmanufacturer.php b/modules/blockmanufacturer/blockmanufacturer.php index 6acf9c2b3..e3d86b544 100644 --- a/modules/blockmanufacturer/blockmanufacturer.php +++ b/modules/blockmanufacturer/blockmanufacturer.php @@ -54,8 +54,7 @@ class BlockManufacturer extends Module function hookLeftColumn($params) { - - $this->smartyAssign(array( + $this->templateAssign(array( 'manufacturers' => Manufacturer::getManufacturers(), 'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'), 'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'), diff --git a/modules/blockmyaccount/blockmyaccount.php b/modules/blockmyaccount/blockmyaccount.php index 9e9769055..aea449ed4 100644 --- a/modules/blockmyaccount/blockmyaccount.php +++ b/modules/blockmyaccount/blockmyaccount.php @@ -61,7 +61,7 @@ class BlockMyAccount extends Module if (!$this->context->customer->isLogged()) return false; - $this->smartyAssign(array( + $this->templateAssign(array( 'voucherAllowed' => (int)Configuration::get('PS_VOUCHERS'), 'returnAllowed' => (int)Configuration::get('PS_ORDER_RETURN'), 'HOOK_BLOCK_MY_ACCOUNT' => Module::hookExec('myAccountBlock'), diff --git a/modules/blocknewproducts/blocknewproducts.php b/modules/blocknewproducts/blocknewproducts.php index 740b43fea..30ea43237 100644 --- a/modules/blocknewproducts/blocknewproducts.php +++ b/modules/blocknewproducts/blocknewproducts.php @@ -100,7 +100,7 @@ class BlockNewProducts extends Module if (!$newProducts AND !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) return; - $this->smartyAssign(array( + $this->templateAssign(array( 'new_products' => $newProducts, 'mediumSize' => Image::getSize('medium'), )); diff --git a/modules/blockspecials/blockspecials.php b/modules/blockspecials/blockspecials.php index cce97310a..2bb7b8e8e 100644 --- a/modules/blockspecials/blockspecials.php +++ b/modules/blockspecials/blockspecials.php @@ -90,7 +90,7 @@ class BlockSpecials extends Module if (!$special = Product::getRandomSpecial((int)$params['cookie']->id_lang) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) return; - $this->smartyAssign(array( + $this->templateAssign(array( 'special' => $special, 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'mediumSize' => Image::getSize('medium'), diff --git a/modules/blockuserinfo/blockuserinfo.php b/modules/blockuserinfo/blockuserinfo.php index d83036b4c..c6b2c2ed8 100644 --- a/modules/blockuserinfo/blockuserinfo.php +++ b/modules/blockuserinfo/blockuserinfo.php @@ -60,7 +60,7 @@ class BlockUserInfo extends Module if (!$this->active) return; - $this->smartyAssign(array( + $this->templateAssign(array( 'cart' => $this->context->cart, 'cart_qties' => $this->context->cart->nbProducts(), 'logged' => $this->context->customer->isLogged(), diff --git a/modules/blockviewed/blockviewed.php b/modules/blockviewed/blockviewed.php index b77ac0181..468de380d 100644 --- a/modules/blockviewed/blockviewed.php +++ b/modules/blockviewed/blockviewed.php @@ -166,7 +166,7 @@ class BlockViewed extends Module if (!sizeof($productsViewedObj)) return ; - $this->smartyAssign(array( + $this->templateAssign(array( 'productsViewedObj' => $productsViewedObj, 'mediumSize' => Image::getSize('medium'))); diff --git a/modules/cheque/cheque.php b/modules/cheque/cheque.php index 07461b107..fb645bded 100644 --- a/modules/cheque/cheque.php +++ b/modules/cheque/cheque.php @@ -1,6 +1,6 @@ tab = 'payments_gateways'; $this->version = '2.3'; $this->author = 'PrestaShop'; - + $this->currencies = true; $this->currencies_mode = 'checkbox'; @@ -51,13 +51,13 @@ class Cheque extends PaymentModule $this->chequeName = $config['CHEQUE_NAME']; if (isset($config['CHEQUE_ADDRESS'])) $this->address = $config['CHEQUE_ADDRESS']; - + parent::__construct(); $this->displayName = $this->l('Check'); $this->description = $this->l('Module for accepting payments by check.'); $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?'); - + if (!isset($this->chequeName) OR !isset($this->address)) $this->warning = $this->l('\'To the order of\' and address must be configured in order to use this module correctly.'); if (!sizeof(Currency::checkPaymentCurrencies($this->id))) @@ -149,26 +149,7 @@ class Cheque extends PaymentModule public function execPayment($cart) { - if (!$this->active) - return ; - - if (!$this->_checkCurrency($cart)) - Tools::redirect('index.php?controller=order'); - - - $this->context->smarty->assign(array( - 'nbProducts' => $cart->nbProducts(), - 'cust_currency' => $cart->id_currency, - 'currencies' => $this->getCurrency((int)$cart->id_currency), - 'total' => $cart->getOrderTotal(true, Cart::BOTH), - 'isoCode' => $this->context->language->iso_code, - 'chequeName' => $this->chequeName, - 'chequeAddress' => Tools::nl2br($this->address), - 'this_path' => $this->_path, - 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' - )); - - return $this->display(__FILE__, 'payment_execution.tpl'); + return $this->actionPayment(true); } public function hookPayment($params) @@ -203,7 +184,7 @@ class Cheque extends PaymentModule $this->context->smarty->assign('status', 'failed'); return $this->display(__FILE__, 'payment_return.tpl'); } - + private function _checkCurrency($cart) { $currency_order = new Currency((int)($cart->id_currency)); @@ -215,4 +196,32 @@ class Cheque extends PaymentModule return true; return false; } + + public function actionPayment($direct_call = false) + { + if (!$this->active) + return ; + + $cart = $this->context->cart; + if (!$this->_checkCurrency($cart)) + Tools::redirect('index.php?controller=order'); + + $this->context->smarty->assign(array( + 'nbProducts' => $cart->nbProducts(), + 'cust_currency' => $cart->id_currency, + 'currencies' => $this->getCurrency((int)$cart->id_currency), + 'total' => $cart->getOrderTotal(true, Cart::BOTH), + 'isoCode' => $this->context->language->iso_code, + 'chequeName' => $this->chequeName, + 'chequeAddress' => Tools::nl2br($this->address), + 'this_path' => $this->_path, + 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/' + )); + + if (!$direct_call) + return $this->getTemplatePath('payment_execution.tpl'); + else + // For retrocompatibility + return $this->display(__FILE__, 'payment_execution.tpl'); + } } diff --git a/modules/cheque/payment.tpl b/modules/cheque/payment.tpl index ce487ff65..18254dadc 100644 --- a/modules/cheque/payment.tpl +++ b/modules/cheque/payment.tpl @@ -1,5 +1,5 @@ {* -* 2007-2011 PrestaShop +* 2007-2011 PrestaShop * * NOTICE OF LICENSE * @@ -25,7 +25,7 @@ *}

- + {l s='Pay by cheque' mod='cheque'} {l s='Pay by cheque (order process will be longer)' mod='cheque'} diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 205af1373..968631b5d 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -96,7 +96,7 @@ class HomeFeatured extends Module $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10)); - $this->smartyAssign(array( + $this->templateAssign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'), diff --git a/override/controllers/front/ModuleController.php b/override/controllers/front/ModuleController.php new file mode 100644 index 000000000..f3a2a8697 --- /dev/null +++ b/override/controllers/front/ModuleController.php @@ -0,0 +1,7 @@ +