// Rename Module->smartyAssign to Module->templateAssign

[+] Front: Add module controller + url dispatch for modules
This commit is contained in:
rMalie committed 2011-09-23 13:50:33 +00:00
1 parent 3c215168ac
commit dc957d3d3a
20 files changed
+122 -52

No files matched your search

+1
View File
@@ -69,6 +69,7 @@ class AdminMeta extends AdminTab
$this->addFieldRoute('manufacturer_rule', $this->l('Route to manufacturer')); $this->addFieldRoute('manufacturer_rule', $this->l('Route to manufacturer'));
$this->addFieldRoute('cms_rule', $this->l('Route to CMS page')); $this->addFieldRoute('cms_rule', $this->l('Route to CMS page'));
$this->addFieldRoute('cms_category_rule', $this->l('Route to CMS category')); $this->addFieldRoute('cms_category_rule', $this->l('Route to CMS category'));
$this->addFieldRoute('module', $this->l('Route to modules'));
} }
} }
+2
View File
@@ -315,6 +315,8 @@
'IndexController' => 'override/controllers/front/IndexController.php', 'IndexController' => 'override/controllers/front/IndexController.php',
'ManufacturerControllerCore' => 'controllers/front/ManufacturerController.php', 'ManufacturerControllerCore' => 'controllers/front/ManufacturerController.php',
'ManufacturerController' => 'override/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', 'MyAccountControllerCore' => 'controllers/front/MyAccountController.php',
'MyAccountController' => 'override/controllers/front/MyAccountController.php', 'MyAccountController' => 'override/controllers/front/MyAccountController.php',
'NewProductsControllerCore' => 'controllers/front/NewProductsController.php', 'NewProductsControllerCore' => 'controllers/front/NewProductsController.php',
+8
View File
@@ -108,6 +108,14 @@ class DispatcherCore
'meta_title' => array('regexp' => '[a-zA-Z0-9-]*'), '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'),
),
),
); );
/** /**
+1 -1
View File
@@ -25,7 +25,7 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
class FrontControllerCore extends ControllerCore class FrontControllerCore extends Controller
{ {
public $errors = array(); public $errors = array();
+34 -10
View File
@@ -118,7 +118,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @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); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -145,7 +145,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @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); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -173,7 +173,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @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)); $base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));
$url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang); $url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang);
@@ -201,7 +201,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @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); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -228,7 +228,7 @@ class LinkCore
* @param int $id_lang * @param int $id_lang
* @return string * @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); $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang);
if (!$id_lang) if (!$id_lang)
@@ -247,6 +247,30 @@ class LinkCore
return $url.Dispatcher::getInstance()->createUrl('manufacturer_rule', $params, $this->allow); 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 * Returns a link to a product image for display
* Note: the new image filesystem stores product images in subdirectories of img/p/ * Note: the new image filesystem stores product images in subdirectories of img/p/
@@ -255,7 +279,7 @@ class LinkCore
* @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new) * @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 * @param string $type
*/ */
public function getImageLink($name, $ids, $type = NULL) public function getImageLink($name, $ids, $type = null)
{ {
// legacy mode or default image // legacy mode or default image
if ((Configuration::get('PS_LEGACY_IMAGES') if ((Configuration::get('PS_LEGACY_IMAGES')
@@ -377,11 +401,11 @@ class LinkCore
{ {
if (Configuration::get('PS_REWRITING_SETTINGS') AND ($k == 'isolang' OR $k == 'id_lang')) if (Configuration::get('PS_REWRITING_SETTINGS') AND ($k == 'isolang' OR $k == 'id_lang'))
continue; 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))); $ifSort = (!$sort OR ($sort AND !in_array($k, $varsSort)));
$ifPagination = (!$pagination OR ($pagination AND !in_array($k, $varsPagination))); $ifPagination = (!$pagination || ($pagination && !in_array($k, $varsPagination)));
if ($ifNb AND $ifSort AND $ifPagination AND !is_array($value)) if ($ifNb && $ifSort && $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)); !$array ? ($vars .= ((!$n++ && ($this->allow == 1 || $url == $this->url)) ? '?' : '&').urlencode($k).'='.urlencode($value)) : ($vars[urlencode($k)] = urlencode($value));
} }
if (!$array) if (!$array)
return $url.$vars; return $url.$vars;
+17 -2
View File
@@ -515,7 +515,7 @@ abstract class ModuleCore
* Return an instance of the specified module * Return an instance of the specified module
* *
* @param string $moduleName Module name * @param string $moduleName Module name
* @return Module instance * @return Module
*/ */
public static function getInstanceByName($moduleName) public static function getInstanceByName($moduleName)
{ {
@@ -1158,6 +1158,21 @@ abstract class ModuleCore
return $result; 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 * 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 string $key Variable key (can be an array)
* @param mixed $value Variable value * @param mixed $value Variable value
*/ */
public function smartyAssign($key, $value = null) public function templateAssign($key, $value = null)
{ {
if (is_array($key)) if (is_array($key))
{ {
+7 -2
View File
@@ -25,5 +25,10 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
$controller = new FrontController(); if (isset(Context::getContext()->controller))
$controller->init(); $controller = Context::getContext()->controller;
else
{
$controller = new FrontController();
$controller->init();
}
+5 -5
View File
@@ -77,10 +77,10 @@ class BlockCart extends Module
if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1) if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1)
{ {
$totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); $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, 'products' => $products,
'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)), 'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)),
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
@@ -98,9 +98,9 @@ class BlockCart extends Module
'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false 'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false
)); ));
if (sizeof($errors)) if (sizeof($errors))
$this->smartyAssign('errors', $errors); $this->templateAssign('errors', $errors);
if(isset($this->context->cookie->ajax_blockcart_display)) 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() public function getContent()
@@ -160,7 +160,7 @@ class BlockCart extends Module
return; return;
// @todo this variable seems not used // @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); $this->assignContentVars($params);
return $this->display(__FILE__, 'blockcart.tpl'); return $this->display(__FILE__, 'blockcart.tpl');
} }
+2 -2
View File
@@ -773,7 +773,7 @@ class BlockCms extends Module
public function displayBlockCMS($column) public function displayBlockCMS($column)
{ {
$cms_titles = self::getCMStitles($column); $cms_titles = self::getCMStitles($column);
$this->smartyAssign(array( $this->templateAssign(array(
'block' => 1, 'block' => 1,
'cms_titles' => $cms_titles, 'cms_titles' => $cms_titles,
)); ));
@@ -796,7 +796,7 @@ class BlockCms extends Module
if (Configuration::get('FOOTER_BLOCK_ACTIVATION')) if (Configuration::get('FOOTER_BLOCK_ACTIVATION'))
{ {
$cms_titles = self::getCMStitlesFooter(); $cms_titles = self::getCMStitlesFooter();
$this->smartyAssign(array( $this->templateAssign(array(
'block' => 0, 'block' => 0,
'cmslinks' => $cms_titles, 'cmslinks' => $cms_titles,
'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'), 'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'),
+1 -1
View File
@@ -92,7 +92,7 @@ class BlockLanguages extends Module
} }
} }
if (count($default_rewrite)) if (count($default_rewrite))
$this->smartyAssign('lang_rewrite_urls', $default_rewrite); $this->templateAssign('lang_rewrite_urls', $default_rewrite);
} }
return $this->display(__FILE__, 'blocklanguages.tpl'); return $this->display(__FILE__, 'blocklanguages.tpl');
@@ -54,8 +54,7 @@ class BlockManufacturer extends Module
function hookLeftColumn($params) function hookLeftColumn($params)
{ {
$this->templateAssign(array(
$this->smartyAssign(array(
'manufacturers' => Manufacturer::getManufacturers(), 'manufacturers' => Manufacturer::getManufacturers(),
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'), 'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'), 'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
+1 -1
View File
@@ -61,7 +61,7 @@ class BlockMyAccount extends Module
if (!$this->context->customer->isLogged()) if (!$this->context->customer->isLogged())
return false; return false;
$this->smartyAssign(array( $this->templateAssign(array(
'voucherAllowed' => (int)Configuration::get('PS_VOUCHERS'), 'voucherAllowed' => (int)Configuration::get('PS_VOUCHERS'),
'returnAllowed' => (int)Configuration::get('PS_ORDER_RETURN'), 'returnAllowed' => (int)Configuration::get('PS_ORDER_RETURN'),
'HOOK_BLOCK_MY_ACCOUNT' => Module::hookExec('myAccountBlock'), 'HOOK_BLOCK_MY_ACCOUNT' => Module::hookExec('myAccountBlock'),
@@ -100,7 +100,7 @@ class BlockNewProducts extends Module
if (!$newProducts AND !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) if (!$newProducts AND !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY'))
return; return;
$this->smartyAssign(array( $this->templateAssign(array(
'new_products' => $newProducts, 'new_products' => $newProducts,
'mediumSize' => Image::getSize('medium'), 'mediumSize' => Image::getSize('medium'),
)); ));
+1 -1
View File
@@ -90,7 +90,7 @@ class BlockSpecials extends Module
if (!$special = Product::getRandomSpecial((int)$params['cookie']->id_lang) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) if (!$special = Product::getRandomSpecial((int)$params['cookie']->id_lang) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
return; return;
$this->smartyAssign(array( $this->templateAssign(array(
'special' => $special, 'special' => $special,
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
'mediumSize' => Image::getSize('medium'), 'mediumSize' => Image::getSize('medium'),
+1 -1
View File
@@ -60,7 +60,7 @@ class BlockUserInfo extends Module
if (!$this->active) if (!$this->active)
return; return;
$this->smartyAssign(array( $this->templateAssign(array(
'cart' => $this->context->cart, 'cart' => $this->context->cart,
'cart_qties' => $this->context->cart->nbProducts(), 'cart_qties' => $this->context->cart->nbProducts(),
'logged' => $this->context->customer->isLogged(), 'logged' => $this->context->customer->isLogged(),
+1 -1
View File
@@ -166,7 +166,7 @@ class BlockViewed extends Module
if (!sizeof($productsViewedObj)) if (!sizeof($productsViewedObj))
return ; return ;
$this->smartyAssign(array( $this->templateAssign(array(
'productsViewedObj' => $productsViewedObj, 'productsViewedObj' => $productsViewedObj,
'mediumSize' => Image::getSize('medium'))); 'mediumSize' => Image::getSize('medium')));
+29 -20
View File
@@ -149,26 +149,7 @@ class Cheque extends PaymentModule
public function execPayment($cart) public function execPayment($cart)
{ {
if (!$this->active) return $this->actionPayment(true);
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');
} }
public function hookPayment($params) public function hookPayment($params)
@@ -215,4 +196,32 @@ class Cheque extends PaymentModule
return true; return true;
return false; 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');
}
} }
+1 -1
View File
@@ -25,7 +25,7 @@
*} *}
<p class="payment_module"> <p class="payment_module">
<a href="{$this_path_ssl}payment.php" title="{l s='Pay by cheque' mod='cheque'}"> <a href="{$link->getModuleLink('cheque', 'payment')}" title="{l s='Pay by cheque' mod='cheque'}">
<img src="{$this_path}cheque.jpg" alt="{l s='Pay by cheque' mod='cheque'}" width="86" height="49" /> <img src="{$this_path}cheque.jpg" alt="{l s='Pay by cheque' mod='cheque'}" width="86" height="49" />
{l s='Pay by cheque (order process will be longer)' mod='cheque'} {l s='Pay by cheque (order process will be longer)' mod='cheque'}
</a> </a>
+1 -1
View File
@@ -96,7 +96,7 @@ class HomeFeatured extends Module
$nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
$products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10)); $products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10));
$this->smartyAssign(array( $this->templateAssign(array(
'products' => $products, 'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home'), 'homeSize' => Image::getSize('home'),
@@ -0,0 +1,7 @@
<?php
class ModuleController extends ModuleControllerCore
{
}