Jump to content

Override Front Controller of Module


VTAdrien

Recommended Posts

Hello,

 

I'm new Prestashop Customer and I have question about Override Controller.

 

I have this addons: https://addons.prestashop.com/en/private-sales-flash-sales/16634-advanced-private-sales-16-15.html

 

I need to add JS file on this addons, so I think I need to Override the Front Controller to make:

$this->addJS(...)

The default file path is:

root/modules/privatesales/controllers/front/home.php

"class PrivatesaleshomeModuleFrontController extends ModuleFrontController"

So, I did this:

root/override/modules/privatesales/controllers/front/home.php

"class PrivatesaleshomeModuleFrontControllerOverride extends PrivatesaleshomeModuleFrontController"

I deleted the file "class_index.php" but It doesn't work..:/

 

I don't know if I forgot something.
I have followed this documentation: http://build.prestashop.com/howtos/module/how-to-override-modules/

 

Can someone help me ?

 

Thank you.

Have a good day.

Link to comment
Share on other sites

En 22/6/2017 a las 11:21 AM, VTAdrien dijo:

Hello,

 

I'm new Prestashop Customer and I have question about Override Controller.

 

I have this addons: https://addons.prestashop.com/en/private-sales-flash-sales/16634-advanced-private-sales-16-15.html

 

I need to add JS file on this addons, so I think I need to Override the Front Controller to make:


$this->addJS(...)

The default file path is:


root/modules/privatesales/controllers/front/home.php

"class PrivatesaleshomeModuleFrontController extends ModuleFrontController"

So, I did this:


root/override/modules/privatesales/controllers/front/home.php

"class PrivatesaleshomeModuleFrontControllerOverride extends PrivatesaleshomeModuleFrontController"

I deleted the file "class_index.php" but It doesn't work..:/

 

I don't know if I forgot something.

I have followed this documentation: http://build.prestashop.com/howtos/module/how-to-override-modules/

 

Can someone help me ?

 

Thank you.

Have a good day.

 

You can't override a module controller.

EDIT: In PS 1.7 it's possible to override module controllers

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

Hi,

 

Thank you for answer.

 

Really ? So what is the purpose of this documentation then: http://build.prestashop.com/howtos/module/how-to-override-modules/ ?

 

If I can't override module controller, do you have solution to add JS file for this module ? Like « blocksearch/blocksearch.js » or something ?

 

Edit: and this https://www.prestashop.com/forums/topic/455661-override-a-module-frontcontroller/

 

? ..

 

Ty.

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

Hi,

 

Thank you for answer.

 

Really ? So what is the purpose of this documentation then: http://build.prestashop.com/howtos/module/how-to-override-modules/ ?

 

If I can't override module controller, do you have solution to add JS file for this module ? Like « blocksearch/blocksearch.js » or something ?

 

Edit: and this https://www.prestashop.com/forums/topic/455661-override-a-module-frontcontroller/

 

? ..

 

Ty.

 

You can override module class, but not module controllers/classes.

Resolved.

 

Thanks anyway :lol:

 

It would be great if you could say the solution you've taken  ;)

Link to comment
Share on other sites

Hi,

 

It's wonderful to hear that ...

 

I'm a professional developer, I guess you too? The solution doesn't seem insurmountable to find.

Anyway, thank you for your helping.

 

My solution:

 

I created this file: root/override/modules/privatesales/privatesales.php with this content:

<?php
..

class PrivatesalesOverride extends Privatesales
{
    ...

    public function hookDisplayHeader($params)
    {
        parent::hookDisplayHeader($params);
        
        $this->context->controller->addJS(_THEME_JS_DIR_.'modules/privatesales/js/privatesales.js');
    }
    
    ...   
}
?>

Don't forget to delete "cache/cache_index.php".

 

I hope I can help some people ;)

 

Have a good day.

 

  • Like 1
Link to comment
Share on other sites

Hi,

 

It's wonderful to hear that ...

 

I'm a professional developer, I guess you too? The solution doesn't seem insurmountable to find.

Anyway, thank you for your helping.

 

My solution:

 

I created this file: root/override/modules/privatesales/privatesales.php with this content:

<?php
..

class PrivatesalesOverride extends Privatesales
{
    ...

    public function hookDisplayHeader($params)
    {
        parent::hookDisplayHeader($params);
        
        $this->context->controller->addJS(_THEME_JS_DIR_.'modules/privatesales/js/privatesales.js');
    }
    
    ...   
}
?>

Don't forget to delete "cache/cache_index.php".

 

I hope I can help some people ;)

 

Have a good day.

 

When you ask help in a forum and you find a solution, the least you can do is share it to other users that could need it  -_-

Link to comment
Share on other sites

When you ask help in a forum and you find a solution, the least you can do is share it to other users that could need it  -_-

 

I understand, it's not the problem but rather the way you approach things, politeness is optional in you?

The ankles should not be swollen.

 

I will not enter into any debate. Thanks for your help :)

Link to comment
Share on other sites

I understand, it's not the problem but rather the way you approach things, politeness is optional in you?

The ankles should not be swollen.

 

I will not enter into any debate. Thanks for your help :)

 

English is not my native language, so maybe it wasn't expressed as I wanted!  :unsure:

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...