How to get product cover image by Product Id in PrestaShop 1.7

In this post I am going to explain how to get product cover image by Product Id in PrestaShop 1.7.

// Your Product Id
$id_product = 10;

// Language id
$id_lang = (int) Configuration::get('PS_LANG_DEFAULT');

// Get cover image for your product
$image = Image::getCover($id_product);

// Load Product Object
$product = new Product($id_product);

// Initialize the link object
$link = new Link;

$imagePath = $link->getImageLink($product->link_rewrite[Context::getContext()->language->id], $image['id_image'], 'home_default');

echo $imagePath;

 

1 Comment

  1. Hello, Sir!
    Where do you write this code?
    I´m a “new guy” in Prestashop, and I can´t set a cover images for my 4000 products.
    Regards.

Leave a Reply

Your email address will not be published. Required fields are marked *