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 have created a test.php file in the shops root directory with following content:
<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'test.tpl');
?>
I placed the corresponding test.tpl in my themes basefolder. It simply contains 'hello world'.
I changed the blockmenu.php and created a custom link to my page:
$this->_menu .= '<li><a href="test.php">TEST</a></li>'.PHP_EOL;
If I click the link the page is displayed but the html is some kind of corrupt. The body-id of the page is set to pagenotfound and the left column is generated but is not shown. Is there any way to set the $page_name for my custom page so that I can check if my custom page is loaded and to supress the generation of the left and right columns?
Is there any other way to create a functional custom page without CMS?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With