How to Create Custom Layout for Specific Product in Prestashop

For any E commerce Platform product Page is one of the important Page for Business point of view. You can customize a Specific product page layout in Presatshop very easily.

Override Product Controller

Step 1: Make a file in override/controllers/front/ProductController.php and add below code:

<?php

class ProductController extends ProductControllerCore
{
    public function initContent()
    {
        /* loading the default code */
        parent::initContent();
        
        /* please add all Product ID for which you want to use this custom template */
        $product_ids = array(5, 6);
        
        if (isset($this->product) && in_array($this->product->id, $product_ids))
        {
            /* please change the file name 'product-custom.tpl'
             to any other file name you want to use in your theme directory,
            i. e. themes/[yourtheme]/product-custom.tpl */
            $this->setTemplate(_PS_THEME_DIR_.'product-custom.tpl');
        } else {
            $this->setTemplate(_PS_THEME_DIR_.'product.tpl');
        }    
    }
}

Step 2: Make a file in themes/[yourtheme]/product-custom.tpl with your custom code.

If still you can not find your changes made in "product-custom.tpl" then you should delete the file "class_index.php" in cache folder. 

Post a Comment

0 Comments