John Davidson

php - How to create Custom Page Prestashop 1.7

0 comments
Message:


I share with you how to create a custom page PHP in Prestashop 1.7


I am showing in this example the brands, but you can show other sql queries, etc


1° Create the controller BrandsJatController.php to /override/controllers/front/


<?php
/**
* @package Class BrandsJatController
* @author Jatniel Guzmán
* @copyright 2020 Jatniel Guzmán
* @license MIT License
* @link https://jatnielguzman.com
* @link https://twitter.com/jatnieldev
*/

class BrandsJatController extends FrontController
{

public $php_self = 'brands';

public function init()
{
parent::init();
}

public function initContent()
{

$brands = $this->getBrands();

$this->context->smarty->assign('lorem', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis lacinia massa.
Fusce ante purus, aliquet eget porttitor ut, sodales in risus. Nunc gravida ipsum id gravida pretium.');

$this->context->smarty->assign('dev', 'Jatniel Guzmán');

$this->context->smarty->assign($brands);

parent::initContent();

// themes/mytheme/templates/brandsjat.tpl
$this->setTemplate('brandsjat.tpl');
}

public function getBrands(){

$brands = Manufacturer::getManufacturers(false, (int)Context::getContext()->language->id);

foreach ($brands as &$brand) {

$brand['image'] = $this->context->language->iso_code.'-default';

$brand['link'] = $this->context->link->getManufacturerLink($brand['id_manufacturer']);

$fileExist = file_exists(
_PS_MANU_IMG_DIR_ . $brand['id_manufacturer'] . '-' .
ImageType::getFormattedName('medium').'.jpg'
);

if ($fileExist) {
$brand['image'] = $brand['id_manufacturer'];
}
}

return array(
'brands' => $brands,
'page_link' => $this->context->link->getPageLink('manufacturer'),
'text_list_nb' => Configuration::get('BRAND_DISPLAY_TEXT_NB'),
'brand_display_type' => Configuration::get('BRAND_DISPLAY_TYPE'),
'display_link_brand' => Configuration::get('PS_DISPLAY_SUPPLIERS'),
);
}

}

2° Create the file brandsjat.tpl to /themes/mytheme/templates/


{**
* Custom Page Brands Prestashop 1.7
*
* @package Class BrandsJatController
* @author Jatniel Guzmán
* @copyright 2020 Jatniel Guzmán
* @license MIT License
* @link https://jatnielguzman.com
* @link https://twitter.com/jatnieldev
*}

{extends file='page.tpl'}

{block name='page_header_container'}{/block}

{block name='page_title'}
<span class="sitemap-title">{l s='Nos Marques' d='Shop.Theme'}</span>
{/block}

{block name='page_content'}
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">NOS MARQUES</h1>
<p class="h4">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis lacinia massa. Fusce ante
purus, aliquet eget porttitor ut, sodales in risus. Nunc gravida ipsum id gravida pretium. Praesent
sodales viverra velit, interdum laoreet ex tempus a. In lacus est, lacinia ac vehicula in, posuere
ac sapien. Morbi vel luctus purus, in lobortis erat.</p>
<div class="row">

{foreach from=$brands item=brand}

{* BOX BRAND *}

<div class="col-md-5 mt-md-5 border border-dark mx-auto l-3">

<div class="float-left w-50">
<img src="{$urls.img_manu_url}{$brand.image}.jpg" class="img-fluid w-75 my-5">
</div>

<div class="float-right w-50">
<h2 class="text-break text-lg-center">{$brand.name}</h2>
<p>
{if !empty($brand.short_description)}
{$brand.short_description|strip_tags:'UTF-8'|truncate:266:'...'}
{else}
{$lorem}
{/if}
</p>
<a href="{$brand.link}" class="">Voir tous les produits</a>
</div>

</div>

{* END BOX BRAND *}

{/foreach}

</div>

</div>
</div>
</div>
{/block}

3° In the back office -> Shop parameters -> Traffic & SEO, and in the "+" Add anew page.



  • Page name, select -> brands.

  • Rewritten URL, we write the url -> example our-brands


verify the url: https://www.myshop-ps.com/our-brands


The code is available from github.com/jatniel/custom_page_prestashop.


Best regards,


Jatniel



My Answer:
I hope this helps you create a custom page in Prestashop 1.7. Let me know if you have any questions or need further assistance. Thank you!

Rate this post

4 of 5 based on 7473 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us