From 890152cb6b8ac742f71a0b0faf7222ddbdc8f6f3 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 24 Jul 2017 16:01:29 +0200 Subject: [PATCH 1/2] [FIX] website_sale, website_sale_options: fix modal prices Backport of 8bd56bb46628e57f41c635f20c527264d7a20d86 OPW 744943 Closes #18416 --- .../static/src/js/website_sale.js | 38 ++++++++++++------- addons/website_sale/views/templates.xml | 3 +- .../website_sale_options/controllers/main.py | 9 +++++ .../static/src/css/website_sale.css | 5 +++ .../static/src/js/website_sale.js | 2 +- .../website_sale_options/views/templates.xml | 8 ++-- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 5f33ed0d11b..8476977b724 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -105,23 +105,31 @@ $('.oe_website_sale').each(function () { $(oe_website_sale).on("change", 'input[name="add_qty"]', function (event) { var product_ids = []; - var product_dom = $(".js_product .js_add_cart_variants[data-attribute_value_ids]").last(); + var product_dom = $(".js_product .js_add_cart_variants[data-attribute_value_ids]"); + var qty = $(event.target).closest('form').find('input[name="add_qty"]').val(); if (!product_dom.length) { return; } - _.each(product_dom.data("attribute_value_ids"), function(entry) { - product_ids.push(entry[0]);}); - var qty = $(event.target).closest('form').find('input[name="add_qty"]').val(); + _.each(product_dom, function(prod) { + _.each($(prod).data("attribute_value_ids"), function(entry) { + if (product_ids.indexOf(entry[0]) === -1) { + product_ids.push(entry[0]); + }}); + }) + + if ($("#product_detail").length) { // display the reduction from the pricelist in function of the quantity ajax.jsonRpc("/shop/get_unit_price", 'call', {'product_ids': product_ids,'add_qty': parseInt(qty)}) .then(function (data) { - var current = product_dom.data("attribute_value_ids"); - for(var j=0; j < current.length; j++){ - current[j][2] = data[current[j][0]]; - } - product_dom.attr("data-attribute_value_ids", JSON.stringify(current)).trigger("change"); + _.each(product_dom, function (prod) { + var current = $(prod).data("attribute_value_ids"); + for(var j=0; j < current.length; j++){ + current[j][2] = data[current[j][0]]; + } + $(prod).trigger("change"); + }); }); } }); @@ -275,17 +283,17 @@ $('.oe_website_sale').each(function () { $(oe_website_sale).on('change', 'input.js_variant_change, select.js_variant_change, ul[data-attribute_value_ids]', function (ev) { var $ul = $(ev.target).closest('.js_add_cart_variants'); var $parent = $ul.closest('.js_product'); - var $product_id = $parent.find('input.product_id').first(); - var $price = $parent.find(".oe_price:first .oe_currency_value") - .add($('#product_confirmation').find(".oe_price")); - var $default_price = $parent.find(".oe_default_price:first .oe_currency_value") - .add($('#product_confirmation').find(".oe_default_price:first .oe_currency_value")); + var $product_id = $parent.find('.product_id').first(); + var $price = $parent.find(".oe_price:first .oe_currency_value"); + var $default_price = $parent.find(".oe_default_price:first .oe_currency_value"); var $optional_price = $parent.find(".oe_optional:first .oe_currency_value"); var variant_ids = $ul.data("attribute_value_ids"); var values = []; + var unchanged_values = $parent.find('div.oe_unchanged_value_ids').data('unchanged_value_ids') || []; $parent.find('input.js_variant_change:checked, select.js_variant_change').each(function () { values.push(+$(this).val()); }); + values = values.concat(unchanged_values); $parent.find("label").removeClass("text-muted css_not_available"); @@ -298,9 +306,11 @@ $('.oe_website_sale').each(function () { }); if (variant_ids[k][3]-variant_ids[k][2]>0.2) { $default_price.closest('.oe_website_sale').addClass("discount"); + $default_price.parent().removeClass('hidden'); $optional_price.closest('.oe_optional').show().css('text-decoration', 'line-through'); } else { $default_price.closest('.oe_website_sale').removeClass("discount"); + $default_price.parent().addClass('hidden'); $optional_price.closest('.oe_optional').hide(); } product_id = variant_ids[k][0]; diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index c4aab9e1e95..c85be40e8e5 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -366,7 +366,8 @@

Product Name