I\'d like to create a custom page in Prestashop 1.5.3 without using CMS.
Unfortunately I can not find any tutorials that are working with 1.5.3.
So far I hav
All is working good except the "public $php_self = 'mypage'".
If you put your file in the override directory (good practice), the identifier "mypage" doesn't be shown on the SEO Menu. But, if you put your controller file in the main directory, it is working.
The classes/Meta.php doesn't scan the override directory, only the root directory (you can see it on line 56 of Meta.php)
Overriding the class Meta.php with this code allow PrestaShop to scan the override directory and add the pages :
class Meta extends MetaCore
{
public static function getPages($exclude_filled = false, $add_page = false)
{
$selected_pages = parent::getPages($exclude_filled, $add_page);
if (!$files = Tools::scandir(_PS_CORE_DIR_.DIRECTORY_SEPARATOR.'override'.DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.'front'.DIRECTORY_SEPARATOR, 'php', '', true))
die(Tools::displayError('Cannot scan override directory'));
$exlude_pages = array(
'category', 'changecurrency', 'cms', 'footer', 'header',
'pagination', 'product', 'product-sort', 'statistics'
);
foreach ($files as $file)
{
if ($file != 'index.php' && !in_array(strtolower(str_replace('Controller.php', '', $file)), $exlude_pages))
{
$class_name = str_replace('.php', '', $file);
$reflection = class_exists($class_name) ? new ReflectionClass(str_replace('.php', '', $file)) : false;
$properties = $reflection ? $reflection->getDefaultProperties() : array();
if (isset($properties['php_self']))
$selected_pages[$properties['php_self']] = $properties['php_self'];
elseif (preg_match('/^[a-z0-9_.-]*\.php$/i', $file))
$selected_pages[strtolower(str_replace('Controller.php', '', $file))] = strtolower(str_replace('Controller.php', '', $file));
elseif (preg_match('/^([a-z0-9_.-]*\/)?[a-z0-9_.-]*\.php$/i', $file))
$selected_pages[strtolower(sprintf(Tools::displayError('%2$s (in %1$s)'), dirname($file), str_replace('Controller.php', '', basename($file))))] = strtolower(str_replace('Controller.php', '', basename($file)));
}
}
return $selected_pages;
}
}
Just create a controller with the name you want for the page, and put it in /overrides/controllers/front/. The name of the controller must be NameyouwantforthepageController.php
Here is a basic class that will work:
class MyPageController extends FrontController {
/**
* Initialize controller
* @see FrontController::init()
*/
public function init() {
parent::init();
}
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent() {
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'my-page.tpl');
}
}
Take a look at the FrontController to see what method you need to override to add functionnalities, for example setMedia()
to add CSS / JS files.
You will then be able to add a pretty url in the back office in the SEO panel.
Hello geys this solution work perfectlly with override also.
1/ in the folder /override create page manufacturer-detail.php and put this code:
include(dirname(FILE).'/config/config.inc.php'); Controller::getController('ManufacturerDetailController')->run();
Tools::displayFileAsDeprecated();
include(dirname(FILE).'/header.php');
$smarty->display(_PS_THEME_DIR_.'manufacturer-detail.tpl');
include(dirname(FILE).'/footer.php');
2/ In the folder /override/controllers/front create page manufacturerDetailController.php and put this code:
class ManufacturerDetailController extends FrontController{
/*public $php_self = 'manufacturer-detail'; */ /* optional */
public function init(){
parent::init();
}
public function initContent(){
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'manufacturer-detail.tpl');
}
/* The following code portion is optional.
* Remove the double-slashes to activate the portion * if you want to use external stylesheet and JavaScript for the page. * Create the CSS and JS files in the css and js directories of the theme accordingly */
//public function setMedia(){
//parent::setMedia();
//$this->addCSS(_THEME_CSS_DIR_.'custom-page.css');
//$this->addJS(_THEME_JS_DIR_.'custom-page.js');
//}
}
3/ in the folder /themes/your-default-theme create page manufacturer-detail.php and put this code:
4/ You can go to SEO & URLs in your back office and add new url
You can access tou your page http://yourstore.com/index?controller=ManufacturerDetail
OR
http://yourstore.com/urr-you-have-added-from-back-office
class CustompageController extends FrontController{
//add js / css required for the custom page
public function setMedia(){
$this->context->controller->addJS(_THEME_JS_DIR_.'custom-page.js');
$this->context->controller->addCSS(_THEME_CSS_DIR_.'custom-page.css');
parent::setMedia();
}
public function initContent(){
//preparingdata for passing to the custom page
$name = 'Gofenice Technologies';
$expert_in = array('Prestashop Development', 'Prestashop Customization', 'Prestashop Custom Module Development', 'Prestashop Page Speed Optimization');
$this->context->smarty->assign(array(
'company_name' => $name,
'expert_in' => $expert_in
));
//data ends-here
//pass data to template file
$this->setTemplate(_PS_THEME_DIR_.'custom-page.tpl');
//show left/ right columns - will be true and shown by default
$this->display_column_left = false;
$this->display_column_right = false;
//call parent initcontent - this is for loading the site's default header, footer, left and right columns
parent::initContent();
}
}
A template for our new custom page - themes/site-current-theme/custom-page.tpl
<h3>{$company_name}</h3>
<p><strong>{l s='Expert In'}</strong></p>
<ul>
{foreach from=$expert_in item=skill}
<li>{$skill}</li>
{/foreach}
</ul>
creating custom front page in prestashop