Jump to content
NemoPS

[FREE TUTORIAL] Adding new tabs and fields to Prestashop products’ back office without overrides

Recommended Posts

Excellent tutorial as always Nemo. Only to point that it's interesting the use of the hook which is triggered when adding a product

public function hookActionProductAdd($params) {
		$this->hookActionProductUpdate($params);
	}

In that case is better use the $params instead of Tools::getValue('id_product') to completely reuse the hookActionProductUpdate

public function hookActionProductUpdate($params) {
		$id_product = $params['product']->id;

Share this post


Link to post
Share on other sites

Hi, and thank you!

 

Uhm... I think I'm missing a point :D what do you mean? After all it's just about getting the product id :) Or....I'm missing the point as always :D

Share this post


Link to post
Share on other sites

And tank you again for sharing those in deep tutorials, I was thinking to put multi language to my tab and with your workaround about this issue (probably a bug of PS as you said) you have saved me a lot of time!!

 

I encourage Prestashop to hire you you to update their Development documentation :)

Share this post


Link to post
Share on other sites

Hi, and thank you!

 

Uhm... I think I'm missing a point :D what do you mean? After all it's just about getting the product id :) Or....I'm missing the point as always :D

 

 

If you want to create the new field when creating a new product you must use the hookActionProductAdd (the hookActionProductUpdate is triggered when updating). So maybe it's interesting call the hookActionProductUpdate inside the hookActionProductAdd.

 

Then when creating a new product the Tools::getValue('id_product'); will return 0 so you can use $id_product = $params['product']->id; which works in the update and in the add as well

Share this post


Link to post
Share on other sites

Awwww :D right, true, yeah i thought that people wouldn't update a new tab as soon as they create a product, that's why I didn't add it :D but it's a nice suggestion, you can add it as a comment to the tut so other people can see it as well :D

Share this post


Link to post
Share on other sites

Awwww :D right, true, yeah i thought that people wouldn't update a new tab as soon as they create a product, that's why I didn't add it :D but it's a nice suggestion, you can add it as a comment to the tut so other people can see it as well :D

 

Yes, that's a very small issue that in general will be invisible. Practically anybody creates a product at one step :P  (when you have the wonderful save and stay button so close :D ).

 

I'll add the comment in the tut.

 

Regards

Share this post


Link to post
Share on other sites

I'm working on a tab module and as well as in your example I need custom javascript for my tab.

 

So as you have indicated in the tut, you need to know when your tab has been loaded via the asynchronous loading that PS has implemented for the product page.

So with the following js it works for the first time, but when you hit save and stay button in the new tab the code it's not fired when  the page has been reloaded... . If you press the button in the others tab it's fired.

$("#product-tab-content-ModuleNewfieldstut").on('loaded', function(){
       //Code fired when the tab has been loaded
        displayFlags(languages, id_language, allowEmployeeFormLang);

})

I've put my js directly in the footer of the new tab tpl and it works, but it's really strange so I've been digging and when you hit save and stay the normal post is used to load the current page with the current tab and there's no need to load the current tab asynchronous so it's not loaded via ajax nor the loaded event is fired by prestashop javascript.

 

So it's seems that you have to take into account that sometimes you can use the ready event  (as usual) and in the great major of cases it will be loaded with ajax so the loaded event must be used.

 

It would be great if Prestashop would take into account this and fire the loaded event for the current tab if loaded without ajax

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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