Reputation: 5087
I'm calling
$imagePath = Link::getImageLink($product->link_rewrite, $id_product, 'home_default');
For example, when the $id_product is 150 , it returns websitepath/img/p/1/5/0/150-home_default.jpg . But when I see the real image_link created for that product id with the browser view source option it's websitepath/img/p/1/2/5/125-home_default.jpg . Isnt that code supposed to return the image links for a product?
Greetings
Upvotes: 1
Views: 8297
Reputation: 1053
getImageLInk
is not static function, so the solid way is
$image = Image::getCover($id_product);
$product = new Product($id_product, false, Context::getContext()->language->id);
$link = new Link();//because getImageLInk is not static function
$imagePath = $link->getImageLink($product->link_rewrite, $image['id_image'], 'home_default');
Upvotes: 1
Reputation: 515
In Prestashop 1.6, getImageLink shouldn't be call statically
$image = Product::getCover((int)$data['id_product']);
$link = new Link;//because getImageLInk is not static function
$data['imagePath'] = $image ? 'http://'.$link->getImageLink($data['link_rewrite'], $image['id_image'], 'medium_default') : false;
Upvotes: 4
Reputation: 3106
The getImageLink
method returns a link to a product image, but the link contains the ID of the image (125) not the ID of the product(150).
The second argument of the method call should be the image ID not the product ID.
First you should get the image ID then you can get the image link:
$image = Image::getCover($id_product);
$imagePath = Link::getImageLink($product->link_rewrite, $image['id_image'], 'home_default');
Upvotes: 2