Jump to content

Doesn't display content on displayRightColumnProduct


giwrgos88
 Share

Recommended Posts

Hello,

 

I'm working on a module for prestashop 1.7 and 1.6 (I'm testing it on 1.7) and I want to display some information on the single page of a product and for that reason I used the displayRightColumnProduct hook. 

The issue is that I cannot see the content that I'm printing from displayRightColumnProduct but If i go to Design -> Positions I can see my module on the right column product section. 

 

Here is my code


<?php
if (!defined('_PS_VERSION_')) {
    exit;
}
class Rating extends Module
{
    public function __construct()
    {
        $this->name                   = 'rating';
        $this->tab                    = 'front_office_features';
        $this->version                = '0.0.0';
        $this->author                 = 'George Panayi';
        $this->ps_versions_compliancy = ['min' => '1.6', 'max' => _PS_VERSION_];
        $this->bootstrap              = true;
        $this->controllers            = [];
        parent::__construct();
        $this->displayName = $this->l('Rating');
        $this->description = $this->l('Test module');
        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
        $this->page = basename(__FILE__, '.php');
    }
    public function install()
    {
        if (!parent::install()
            || !$this->registerHook('displayRightColumnProduct')
        ) {
            return false;
        }
        return true;
    }
  
    public function uninstall()
    {
        if (!parent::uninstall()
        ) {
            return false;
        }
        return true;
    }
	
	public function hookdisplayRightColumnProduct($params)
    {
        return $this->display(__FILE__, 'rating.tpl');
    }
}

 

Here is my rating.tpl (mymodulename/views/templates/hook/rating.tpl)

This is a test

Do you know what I'm doing wrong?

Edited by giwrgos88
Added module class (see edit history)

Share this post


Link to post
Share on other sites

That source only display in RIGHT column of website

- When you view a product detail page -> No RIGHT column in this page -> Nothing display

- When you view some another pages -> It have displayRightColumn hook

But

 $product = new Product((int) Tools::getValue('id_product')); -> NOT EXIST id_product
So this block code will be executed
        if (!Validate::isLoadedObject($product)) {
            return false;
        }
Function returned: FALSE

it does not load template

Share this post


Link to post
Share on other sites

@tdsoft As I said I want to display it in the single product page, not on the category page that's why I'm using the displayRightColumnProduct.  As for the $product = new Product((int) Tools::getValue('id_product')) you are right but event if you do var_dump or just return the tpl file with static text it doesn't display it.

Share this post


Link to post
Share on other sites

Hi All,

Below codes are working fine for me.

Please check all.

First Go To PrestaShop Admin->Design->Theme & Logo > Theme

On Left Side page column value "product" ->assign layout to value "Two Columns, small right column - Two columns with a small right column".

Please check below screenshot.

Selection_079.thumb.png.79626ff46e92b36561f23f0f77213048.png

Then Create a custom module as per your requirement.

Module:

----------

<?php
if (!defined('_PS_VERSION_')) {
    exit;
}

// Code for Order Download End

class letfColumnProduct extends Module
{

    /* @var boolean error */
    protected $_errors = false;

    public function __construct()
    {
        $this->name = 'letfcolumnproduct';
        $this->tab = 'letfcolumnproduct'; 
        $this->version = '1.0.0';
        $this->author = 'Radhanatha';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('InkXE Letf Button');
        $this->description = $this->l('Integrates the Letf Column Button on Product Details Page.');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

        if (!Configuration::get('MYMODULE_NAME')) {
            $this->warning = $this->l('No name provided');
        }

    }

    /**
     * Installation code of this module
     *
     * @param NULL
     *
     */
    public function install()
    {
        if (Shop::isFeatureActive()) {
            Shop::setContext(Shop::CONTEXT_ALL);
        }

        return parent::install() &&

        // CUSTOMIZE BUTTON HOOKS
        $this->registerHook('displayRightColumnProduct') &&

        Configuration::updateValue('MYMODULE_NAME', 'shopping cart changes');
    }

    /**
     * Un-instal code of this module
     *
     * @param NULL
     *
     */
    public function uninstall()
    {
        if (!parent::uninstall()) {
            return false;
        }

        return true;
    }

    /**
     * Show product custom buton in store front end
     *
     * @param NULL
     *
     */
    public function hookDisplayRightColumnProduct()
    {
        
        $this->context->smarty->assign(
            array(
                'my_module_name' => Configuration::get('MYMODULE_NAME'),
                'my_module_link' => $this->context->link->getModuleLink('letfcolumnproduct', 'display'),
            )
        );
        return $this->display(__FILE__, 'letfcolumnproduct.tpl');
    }

    
}
 

Edited by Radhanatha (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More