In this post I am going to explain how to get all images of product by Product Id in PrestaShop 1.7.
// Your Product Id
$id_product = 10;
// Language id
$id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
// Load Product Object
$product = new Product($id_product);
// Validate CMS Page object
if (Validate::isLoadedObject($product)) {
// Get product images
$productImages = $product->getImages((int) $id_lang);
if ($productImages && count($productImages) > 0) {
// Initialize the link object
$link = new Link;
foreach ($productImages AS $key => $val) {
// get image id
$id_image = $val['id_image'];
// If required check image is cover or not
$cover = $val['cover'];
// Create image path using link object
$imagePath = $link->getImageLink($product->link_rewrite[Context::getContext()->language->id], $id_image, 'home_default');
echo $imagePath . "<br>";
}
// Print Product Images Array If Required
echo "<pre>";
print_r($productImages);
exit;
}
}
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!



Leave a Reply