Jump to content

Help: Override Not Working


Recommended Posts

Still a little new to prestashop.  Only been making modules for a few months, but this is my 4th module and for some reason I can not get the override working.  I'm trying to change the template files being loaded for product.tbl.  The module installs perfectly. So far, this is my file structure.  

 

  • lgs_matrix (main module folder)
    • classes
    • controllers
    • override
      • controllers
        • front
          • ProductController.php
    • css
    • js
    • process
    • storage
    • views
      • templates
        • admin
        • front
          • product.tpl

 

 

 

 

So I've seen this code on a few modules before.  Within the override controller, they have code like this (in ProductController.php).

class ProductController extends ProductControllerCore {

    public function getMatrixTemplateDir() {
        return _PS_MODULE_DIR_ . 'lgs_matrix/views/templates/front/';
    } // END public function getMatrixTemplateDir() {

    public function setTemplate($template) {
			
	if (!Module::isEnabled('lgs_matrix')) {
           return parent::setTemplate($template);		
        }

        if (substr($template, -11) == 'product.tpl') {	
            return parent::setTemplate($this->getMatrixTemplateDir() . 'product.tpl');
        }

        return parent::setTemplate($template);
    } // END public function setTemplate($template) {

} // END class ProductController extends ProductControllerCore {

The last function just switches the product.tpl directories to the modules version.

 

As of right now, the product.tpl is identical to the default one, but for a border around the middle container.  I did this to see if its loading.

 

After several tries, I can not seem to get it working. Clearing cache did not work.  I have even inserted this code into the functions of the module.

echo "<script type=\"application/javascript\">console.log(\"LGS ERROR 1\")</script>";

I see on the console the message everywhere BUT in the override controller. Do I have something wrong?  Pointer or tips?

 

Thanks for any help/

 

 

 

Link to comment
Share on other sites

Hi, the product.tpl file is not your theme's product.tpl file but your module's file.

 

Is there a way to override the product.tbl file which prestashop uses to display a product?

 

Also, why is the ProductController.php not being overridden?

Edited by wstar (see edit history)
Link to comment
Share on other sites

Modifying themes from a module is not recommended.

 

I usually apply some sort of DOM manipulation with JavaScript.

 

I don't know if you want to release the module or just keep it for yourself, but keep in mind that people will have different themes and thus overriding a theme file is not possible.

 

Thanks, make sense!

Link to comment
Share on other sites

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
×
×
  • Create New...