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

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?