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.

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

报告相同问题?