douji7399
2019-05-10 02:01
浏览 82
已采纳

如何在PrestaShop 1.7中使用javascript更改当前产品封面照片

I am trying to set customized product preview (t-shirt with uploaded logotype) as product thumbnail. It's image, file type: jpeg - I have full url with http: NEW_PRODUCT_THUMB.

How to set this url as product image / cover / thumbnail?

For tests, I tried to set it with jQuery:

// <section id="main"> , first <img> child element
$('section#main img:eq(0)').attr("src", NEW_PRODUCT_THUMB );

Problem: Every changes - t-shirt size, color are triggering refresh product page, and then - default image was loaded (from database, not from my customization JS editor).

Here is webpage, where customized product image is set as thumbnail in correct way, but I have no idea how? https://products.printzware.com/home/114-faded-short-sleeves-tshirt.html#/4-size-one_size

图片转代码服务由CSDN问答提供 功能建议

我正在尝试设置自定义产品预览 T-shirt with uploaded 标识作为产品缩略图。 它的图像,文件类型:jpeg - 我有完整的URL与http: NEW_PRODUCT_THUMB

如何将此网址设置为产品图片 / cover / thumbnail?

对于测试,我尝试使用jQuery设置它:

  //&lt; section id =“main”&gt;  ,首先&lt; img&gt; 子元素
 $('section #main img:eq(0)')。attr(“src”,NEW_PRODUCT_THUMB); 
   
 
 

问题: 每次更改 - T恤尺寸,颜色都会触发刷新产品页面,然后 - 加载默认图像(来自数据库,而不是来自我的自定义JS编辑器)。

此处 是网页,其中自定义产品图像以正确的方式设置为缩略图,但我不知道如何? https://products.printzware.com/home/114-faded-short-sleeves-tshirt.html#/4-size-one_size

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumeitang572461 2019-05-10 16:30
    已采纳

    Solution #1

    Why not editing your product.tpl Smarty template file and add a condition stating that if this product has been customized within the current shopping, you display a specific image, instead of the cover one?

    You can retrieve the customized image by calling the following method from the Cart class:

    getProductCustomization($id_product, $type = null, $not_in_cart = false)
    

    And for the real-time modifications, you can of course keep your jQuery code.

    Solution #2

    Same logic, but instead, you can override the getImageLink() method in the Link class.

    Once your override is ready, you can call it dynamically via an ajax call with jQuery.

    This will work even if the page is reloaded.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题