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.

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

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站