monne Posted December 6, 2018 Share Posted December 6, 2018 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 More sharing options...
Apar Posted December 11, 2018 Share Posted December 11, 2018 $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 More sharing options...
monne Posted December 12, 2018 Author Share Posted December 12, 2018 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 More sharing options...
Daresh Posted December 12, 2018 Share Posted December 12, 2018 But it's there in the code in $image['url'] Link to comment Share on other sites More sharing options...
monne Posted December 12, 2018 Author Share Posted December 12, 2018 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 More sharing options...
monne Posted December 12, 2018 Author Share Posted December 12, 2018 47 minutes ago, Daresh said: But it's there in the code in $image['url'] you're right hahaha thanks! Link to comment Share on other sites More sharing options...
Striker Production Posted November 10, 2021 Share Posted November 10, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now