Jump to content

Get carriers list o product.tpl


Recommended Posts


I will try add list of carriers available to current product. I search for resolution about and I saw this:


so, in ../controllers/front/ProductController.php in line 279 I added this code:

'carriers' => $this->product->getCarriers(),


and in my product.tpl:



results it's:

Array ( ) 1


also tried:

{foreach from=$carriers item=carrier} 


then nothing shows up.


Could you help me? Thanks.


My prestashop version:

Link to comment
Share on other sites

  • 2 months later...

We want to tell you that your code will return the result empty when no specific carrier is selected for the respective product.

Image for your reference: https://nimb.ws/Zgkb5j

To resolve the issue, you need to use an if condition to check the result and if the result is empty then you can use the Carrier class of the Prestahsop to get all the available carriers.
You need to add the below code in the ProductController.php before assigning the product data to the tpl.

File path: YOUR_PRESTASHOP_DIRECTORY/controllers/front/ProductController.php

    $carriers = $this->product->getCarriers();
     if(count($carriers) == 0) {
            $carriers = Carrier::getCarriers($this->context->language->id, true, false, false, null, Carrier::ALL_CARRIERS);

Also, you need to assign the data to the product.tpl which is available in the $carriers variable.

  'carriers' => $carriers,

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