Jump to content

How to display manufacturer name on productscategory module?


houkangle

Recommended Posts

How to display manufacturer name on productscategory module?

 

I try to add 

'product_manufacturer' => new Manufacturer((int)$this->product->id_manufacturer, $this->context->language->id),

in productscategory.php.

 

and add 

{$product->manufacturer_name|escape:'htmlall':'UTF-8'}

in productscategory.tpl

 

 

 

but it doesn't work.  Who can help me ?

 

Link to comment
Share on other sites

In the productcategory tpl, the loop is using categoryProduct

 

You don't need to change any php (revert your changes).

In the tpl, during the loop, where ever you need the name do that:

{Manufacturer::getNameById($categoryProduct.id_manufacturer)|escape:'htmlall':'UTF-8'}
  • Like 2
Link to comment
Share on other sites

Thanks Doekia, that will do. :-)

Just for understanding's sake, If you want to do it your way, You should have used the newly created 'product_manufacturer' which you created in your PHP file in your TPL file :-) (That was the purpose of creating it in the first place...)

So then in the TPL file use something like {$product_manufacturer->name|escape:'htmlall':'UTF-8'} or so...

 

pascal

Link to comment
Share on other sites

Initial way proves to be bad and more on the long run since you need to tamper with the native module code.

We can call any static method from smarty v3 (and v2 too at a cost of an intermediate var)

 

That is what we do in my example (prestashop's code is pristine).

We clone the productscategory.tpl within the theme (themes/<your-theme>/modules/productscategory.tpl

We acces within the loop the loop item data (the way the initial code does).

We call the Manufacturer::getNameById() static method.

 

On the long run the worst you have to fear about is the loop item get renamed ... but:

A/ If the module is upgraded for bug fix it still work

B/ Your changes are sandboxed within your theme

C/ We don't need to create yet another set of instances of Manufacturer (memory optimisation)

D/ The code did not do good at first since it was using the id_manufacturer of the product not the one from each products in the same category. You'll have to make any array linked to id_product... Painfull and inefficient

Link to comment
Share on other sites

Hi Doekia,

Fully True. Great explanation. My addition was more for explaining the use of the smarty variable that houkangle created in the first place. Fully agree that minimizing any change to core PrestaShops is a must, especially with the many PrestaShop upgrades that come by every year. :-)

 

Thanks again for the detailed info why your way is the way to go!

 

Merry Christmas,

pascal.

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