Last active
December 21, 2015 01:09
-
-
Save bumbu/6225669 to your computer and use it in GitHub Desktop.
Front page links in admin of Prestashop 1.5.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// override/classes/Dispatcher.php | |
class Dispatcher extends DispatcherCore | |
{ | |
public static $controllerType = null; | |
public function getInstanceCustom($controllerType = 'public') { | |
self::$controllerType = $controllerType; | |
$dispatcher = new Dispatcher(); | |
self::$controllerType = null; | |
return $dispatcher; | |
} | |
protected function __construct() | |
{ | |
$this->use_routes = (bool)Configuration::get('PS_REWRITING_SETTINGS'); | |
if (self::$controllerType) { | |
switch (self::$controllerType) { | |
case 'admin': | |
$this->front_controller = self::FC_ADMIN; | |
$this->controller_not_found = 'adminnotfound'; | |
$this->default_controller = 'adminhome'; | |
$this->use_routes = false; | |
break; | |
case 'module': | |
$this->front_controller = self::FC_MODULE; | |
$this->controller_not_found = 'pagenotfound'; | |
$this->default_controller = 'default'; | |
break; | |
case 'front': | |
default: | |
$this->front_controller = self::FC_FRONT; | |
$this->controller_not_found = 'pagenotfound'; | |
$this->default_controller = 'index'; | |
break; | |
} | |
} else { | |
// Select right front controller | |
if (defined('_PS_ADMIN_DIR_')) | |
{ | |
$this->front_controller = self::FC_ADMIN; | |
$this->controller_not_found = 'adminnotfound'; | |
$this->default_controller = 'adminhome'; | |
$this->use_routes = false; | |
} | |
elseif (Tools::getValue('fc') == 'module') | |
{ | |
$this->front_controller = self::FC_MODULE; | |
$this->controller_not_found = 'pagenotfound'; | |
$this->default_controller = 'default'; | |
} | |
else | |
{ | |
$this->front_controller = self::FC_FRONT; | |
$this->controller_not_found = 'pagenotfound'; | |
$this->default_controller = 'index'; | |
} | |
} | |
$this->setRequestUri(); | |
// Switch language if needed (only on front) | |
if (in_array($this->front_controller, array(self::FC_FRONT, self::FC_MODULE))) | |
Tools::switchLanguage(); | |
if (Language::isMultiLanguageActivated()) | |
$this->multilang_activated = true; | |
$this->loadRoutes(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Usage | |
Context::getContext()->link->getPageLinkCustom('order', true, null, array('step'=>1, 'id_order'=>1), false, 'front'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// override/classes/Link.php | |
class Link extends LinkCore | |
{ | |
public function getPageLinkCustom($controller, $ssl = false, $id_lang = null, $request = null, $request_url_encode = false, $controllerType = 'public') | |
{ | |
$controller = Tools::strReplaceFirst('.php', '', $controller); | |
if (!$id_lang) | |
$id_lang = (int)Context::getContext()->language->id; | |
if (!is_array($request)) | |
{ | |
// @FIXME html_entity_decode has been added due to '&' => '%3B' ... | |
$request = html_entity_decode($request); | |
if ($request_url_encode) | |
$request = urlencode($request); | |
parse_str($request, $request); | |
} | |
$uri_path = Dispatcher::getInstanceCustom($controllerType)->createUrl($controller, $id_lang, $request); | |
$url = ($ssl && $this->ssl_enable) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true); | |
$url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/'); | |
return $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment