Jump to content

How to define a js file in the right place for widget module

Recommended Posts

I had created a module prestashop  using  "extends Module implements WidgetInterface"  and i added js file in construct function  every things works  , when i call a method with ajax a resive an erreur

" Uncaught Error: Call to a member function registerJavascript() on null in /var/www/html/PrestaShop-
Stack trace:
#0 [internal function]: Ns_MonModule->__construct()

#1 /var/www/html/PrestaShop- ReflectionClass->newInstance()
#2 /var/www/html/PrestaShop- PrestaShop\PrestaShop\Core\Foundation\IoC\Container->makeInstanceFromClassName('ns_monmodule', Array)
#3 /var/www/html/PrestaShop- PrestaShop\PrestaShop\Core\Foundation\IoC\Container->doMake('ns_monmodule', Array)
#4 /var/www/html/PrestaShop- PrestaShop\PrestaShop\Core\Foundation\IoC\Container->make('ns_monmodule')
#5 /var/www/html/PrestaShop- PrestaShop\PrestaShop\Adapter\ServiceLocator::get('ns_monmodule')
#6 /var/www/html/PrestaShop- Modul in <b>/var/www/html/PrestaShop-</b> on line <b>54</b><br />

i nedd to konw how to define in the right place and use ajax to call methods from controllers a file js in a module , thanks in advance 

Capture d’écran de 2020-12-10 12-11-32.png

Capture d’écran de 2020-12-10 12-10-40.png

Share this post

Link to post
Share on other sites

Add the JS in a hook e.g. hookHeader or hookActionFrontControllerSetMedia and add an if-clause to check the type of controller to load it only when really required.

  • Like 1

Share this post

Link to post
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...

Important Information

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