Jump to content

Recommended Posts

Hello fellows,
 
I am having troubles getting our "old" plugin to work with the new Prestashop 1.7
The method addJs doesn't include the scripts anymore and the new method registerJavascript doesn't allow urls e.g. cdnjs
I solved it that I added the script tag to the template which is quite a bad practice, but I really didn't know how to work around it.
 
Another issue is regarding the setForm in PaymentOption class. When I load the tplcontaining the form and add a listener to the form (onsubmit) then the form doesn't get submitted as the documentation says in the github.

 

Does anybody have these issues too?

Share this post


Link to post
Share on other sites

Try using registerJavascript & registerStylesheet to set js or css file to templates

$this->context->controller->registerStylesheet(
            'module-mymodule-style',
            'modules/'.$this->name.'/assets/css/my-popup.css',
            [
              'media' => 'all',
              'priority' => 200,
            ]
        );
  • Like 1

Share this post


Link to post
Share on other sites

The method addJs doesn't include the scripts anymore and the new method registerJavascript doesn't allow urls e.g. cdnjs

 

As you can see, I already mentioned that the method doesn't work with remote javascript e.g. cdnjs. It accepts only local scripts.

Edited by LightlynX (see edit history)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hello arnaud,

 

ps 1.7.0.2 actually solves this problem. The developer named aleeks made a pull request which was merged few days ago and it does indeed support the remote resource loading. Have a look at http://stackoverflow.com/questions/40763815/add-remote-javascript-to-prestashop-1-7/41000834#41000834 Or to be more specific https://github.com/PrestaShop/PrestaShop/pull/7022

 

I hope this answer brings smile to all our faces :)

  • Like 2

Share this post


Link to post
Share on other sites

 

Try using registerJavascript & registerStylesheet to set js or css file to templates

$this->context->controller->registerStylesheet(
            'module-mymodule-style',
            'modules/'.$this->name.'/assets/css/my-popup.css',
            [
              'media' => 'all',
              'priority' => 200,
            ]
        );

 

 

Thank you, phinq1910, that is the correct solution. 

 

I tried also the solution on StackOverflow:

$this->registerJavascript('remote-bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', ['server' => 'remote', 'position' => 'bottom', 'priority' => 20]);

But it doesn't work and I get PHP Fatal Error:

Uncaught Error: Call to undefined method Ptm_Testimonials::registerJavascript()

I run on Prestashop 1.7.0.2

Share this post


Link to post
Share on other sites

Thank you, phinq1910, that is the correct solution. 

 

I tried also the solution on StackOverflow:

$this->registerJavascript('remote-bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', ['server' => 'remote', 'position' => 'bottom', 'priority' => 20]);

But it doesn't work and I get PHP Fatal Error:

Uncaught Error: Call to undefined method Ptm_Testimonials::registerJavascript()

I run on Prestashop 1.7.0.2

Do you extend a controller? registerJavascript is a member of Controller class. Therefore you either extend some the controller class or you acquire your context and access its controller where you can acces the member method registerJavascript. e.g.

$context = $this->getContext();
$context->controller->registerJavascript(...);

I hope this clears something for you.

  • Like 1

Share this post


Link to post
Share on other sites

  • 4 months later...

Hi i have a strange problem with registerStylesheet i set media => 'screen and (min-width:769px)' but the output continue to insert "all" and ignore my setting.

 

Someone have noted this issue?

 

Thanks, sorry about OT but apparently this thread is the only one on registerstylesheet

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
 Share

×
×
  • Create New...

Important Information

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