
Displaying more Supplier information on the Product Page in PrestaShop
Displaying more information about a product’s Supplier, directly on the product page, is quite easy in PrestaShop. It only needs an override and a tiny modification to the product template.
Overriding the Product Controller
Unless you want to hard-modify the original ProductController, you would need an override to assign all the necessary Supplier data to your product page.
Create a new file in override/controllers/front, and name it ProductController.php. Open it up and add some generic override code inside php tags:
class ProductController extends ProductControllerCore { }
We have to override the initContentMethod
class ProductController extends ProductControllerCore { public function initContent() { parent::initContent(); } }
Make sure you call the parent at the very beginning of it, then add the following inside:
if($this->product->id_supplier) { $id_supplier_address = Address::getAddressIdBySupplierId($this->product->id_supplier); $supplier_address = new Address($id_supplier_address); }
First off, we are checking the current product has a supplier. Then, we need its address id, which we use to instantiate a new Address object that contains all of the information we seek.
At this point, we can simply assign all we want to the template:
if (Validate::isLoadedObject($supplier_address)) { $this->context->smarty->assign(array( 'supplier_country'=> $supplier_address->country, 'supplier_company'=> $supplier_address->company, 'supplier_address1'=> $supplier_address->address1, 'supplier_postcode'=> $supplier_address->postcode, 'supplier_city'=> $supplier_address->city, 'supplier_phone'=> $supplier_address->phone, 'supplier_state' => State::getNameById($supplier_address->id_state), 'supplier_vat_number'=> $supplier_address->vat_number, )); }
As an extra measure, we make sure the loaded address object is valid and exists
When you’re done modifying the file, reach the cache/ folder and erase class_index.php
Amending the product template
Now we are ready to display our data. Open product.tpl, located in your theme’s folder. You can choose any spot, I decided to go for the area below the social links in the center column.
{if $product->id_supplier} <h4><a href="{$link->getSupplierLink($product->id_supplier)}"><strong>{$product->supplier_name}</strong></a></h4> <ul> <li>{$supplier_address1}</li> <li>{$supplier_postcode}</li> <li>{$supplier_city}, {$supplier_state}</li> <li>{$supplier_country}</li> {if $supplier_vat_number} <li>{$supplier_vat_number}</li> {/if} </ul> {/if}
I am obviously checking if this product has a supplier, otherwise those variables would not be assigned. Save and refresh, you might need to clear cache in the back office (Advanced Parameters, Performance). We’re done!