diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2015-11-10 15:36:56 +0100 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2015-11-10 16:34:57 +0100 |
| commit | a8ae94485dc162b2bfb010b4eadfa1bf82a74ac6 (patch) | |
| tree | f2bc51ca08fb004e286dae81a58f3fcd8c482a64 | |
| parent | 15b0596c3105b4cbff53bb0904feb1f8fe353806 (diff) | |
[FIX] website_sale: unify image update when change variant
The variants on a product in the ecommerce can appear:
- naturally, not a list, colored square for color, ...
- in a list of radio button.
To have the second kind, we need to enable the "List View of Variants"
customize option.
One part of the code was not the same which cause an issue when saving
the image of the variant, it was saved on the product.template instead.
This commit add an "update_product_image" function which is now called
in both scenario.
first half of:
opw-654279
forward port note: in 9.0 website/image -> web/image
| -rw-r--r-- | addons/website_sale/static/src/js/website_sale.js | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index f7fe7a58364..11f7aec7365 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -1,4 +1,12 @@ $(document).ready(function () { + +function update_product_image(event_source, product_id) { + var $img = $(event_source).closest('tr.js_product, .oe_website_sale').find('span[data-oe-model^="product."][data-oe-type="image"] img:first, img.product_detail_img'); + $img.attr("src", "/website/image/product.product/" + product_id + "/image"); + $img.parent().attr('data-oe-model', 'product.product').attr('data-oe-id', product_id) + .data('oe-model', 'product.product').data('oe-id', product_id); +} + $('.oe_website_sale').each(function () { var oe_website_sale = this; @@ -146,9 +154,7 @@ $('.oe_website_sale').each(function () { var $parent = $(this).closest('.js_product'); $parent.find(".oe_default_price:first .oe_currency_value").html( price_to_str(+$(this).data('lst_price')) ); $parent.find(".oe_price:first .oe_currency_value").html(price_to_str(+$(this).data('price')) ); - - var $img = $(this).closest('tr.js_product, .oe_website_sale').find('span[data-oe-model^="product."][data-oe-type="image"] img:first, img.product_detail_img'); - $img.attr("src", "/website/image/product.product/" + $(this).val() + "/image"); + update_product_image(this, +$(this).val()); }); $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change, ul[data-attribute_value_ids]', function (ev) { @@ -184,10 +190,7 @@ $('.oe_website_sale').each(function () { } if (product_id) { - var $img = $(this).closest('tr.js_product, .oe_website_sale').find('span[data-oe-model^="product."][data-oe-type="image"] img:first, img.product_detail_img'); - $img.attr("src", "/website/image/product.product/" + product_id + "/image"); - $img.parent().attr('data-oe-model', 'product.product').attr('data-oe-id', product_id) - .data('oe-model', 'product.product').data('oe-id', product_id); + update_product_image(this, product_id); } $parent.find("input.js_variant_change:radio, select.js_variant_change").each(function () { |
