-1

您将如何在 Prestashop 中使用 javascript 获取产品图片?我已经知道在 tpl 和 php 你可以使用它

$imagePath = Link::getImageLink($product['link_rewrite'], $product['id_product'], 'home_default'); 

{$link->getImageLink($product.link_rewrite, $product.id_product, 'home_default')}`

这可以在javascript中做到这一点吗?

4

3 回答 3

0

Had the same question thats why i entered this 'stack'

Challenge: Wanted image with different sizes then default product.image size in #layer_cart

Solution: Made an image with name popup_default in the BO of prestashop.

In /themes/theme_name/modules/blockcart/blockcart-json.tpl added the following at line 36

"image_popup": {$link->getImageLink($product.link_rewrite, $product.id_image, 'popup_default')|json_encode},

Then in /themes/theme_name/js/modules/blockcart/ajax-cart.js made the following change at line 737

$('.layer_cart_img').html('<img class="layer_cart_img img-responsive" src="' + product.image + '" alt="' + product.name + '" title="' + product.name + '" />');

into

$('.layer_cart_img').html('<img class="layer_cart_img img-responsive" src="' + product.image_popup + '" alt="' + product.name + '" title="' + product.name + '" />');

Now i use an image with 'popup' sizes

于 2015-02-20T12:40:44.820 回答
0

如果你在同一个 tpl 中使用你的 javascript 文件,那么你可以写这个。

{$link->getImageLink($product.link_rewrite, $product.id_product, 'home_default')}

如果您想从外部文件中获取产品图像,则可以使用product_image 类找到产品图像 。

.product_image img

它将帮助您获取产品图像。

于 2013-06-27T23:21:00.680 回答
0

您可以使用: $('img#ID-of-your-img').attr('src') 这将返回图像的链接;)。

于 2013-07-06T18:22:40.003 回答