Jump to content

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


NemoPS

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;
Link to comment
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

Link to comment
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

Link to comment
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

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