Jump to content

Get all images from products on Prestashop 1.7


Recommended Posts

Hi all,

I need to recover all the images of the products. I'm using the codes below, but they only retrieves the link from the first image.

$image = Image::getCover($product['id_product']);
$productus = new Product($product['id_product'], false, Context::getContext()->language->id);
$link = new Link();
$imagePath = $link->getImageLink($productus->link_rewrite, $image['id_image'], 'home_default');
$image = Product::getCover((int)$product['id_product']);
$image = new Image($image['id_image']);
$product_photo = json_encode(_PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg");

 

Have any method that can retrieves all the images from one product?

Thanksss

Link to comment
Share on other sites

$anyproduct = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);

$images = $anyproduct->getImages($this->context->language->id); (Returns all the images data for a product)

$list_image = array();

        foreach ($images as $img) {

            $image['cover'] = (bool)$img['cover'];

            $image['url'] = $this->context->link->getImageLink($anyproduct->link_rewrite, $img['id_image'], 'home_default');

            $image['position'] = $img['position'];

            array_push($list_image,$image);

        }

 

Link to comment
Share on other sites

On 12/11/2018 at 9:29 AM, Apar said:

$anyproduct = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);

$images = $anyproduct->getImages($this->context->language->id); (Returns all the images data for a product)

$list_image = array();

        foreach ($images as $img) {

            $image['cover'] = (bool)$img['cover'];

            $image['url'] = $this->context->link->getImageLink($anyproduct->link_rewrite, $img['id_image'], 'home_default');

            $image['position'] = $img['position'];

            array_push($list_image,$image);

        }

 

Hi, thanks for your time.

I tried that, but it's not what I really want. I need retrieve the url from all the images from the products.

Like this:

http://localhost/prestashop/br/home/19-customizable-mug.html

 

Link to comment
Share on other sites

  • monne changed the title to Get all images from products on Prestashop 1.7
On 12/11/2018 at 9:29 AM, Apar said:

$anyproduct = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);

$images = $anyproduct->getImages($this->context->language->id); (Returns all the images data for a product)

$list_image = array();

        foreach ($images as $img) {

            $image['cover'] = (bool)$img['cover'];

            $image['url'] = $this->context->link->getImageLink($anyproduct->link_rewrite, $img['id_image'], 'home_default');

            $image['position'] = $img['position'];

            array_push($list_image,$image);

        }

 

hahah I'm sorry.. idk why that don't worked before, but now with that code I get what I need. Thanks againnn!!!

$image['url'] = $this->context->link->getImageLink($anyproduct->link_rewrite, $img['id_image'], 'home_default');

 

Link to comment
Share on other sites

  • 2 years later...

My Solution:

$images = Image::getImages($id_lang, $product['id_product'], $idProductAttribute = null);
$list_images = array();
foreach ($images as $img) 
{
 $link = new Link();
 $image = new Image($img['id_image']);
 $image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";
 array_push($list_images,$image_url);
}

All images are in $list_images.

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