diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 4df7d5dbb98..6273be817ca 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -128,16 +128,17 @@ class WebsiteSale(http.Controller): (variant id, [visible attribute ids], variant price, variant sale price) """ # product attributes with at least two choices - product = product.with_context(quantity=1) + quantity = product._context.get('quantity') or 1 + product = product.with_context(quantity=quantity) visible_attrs_ids = product.attribute_line_ids.filtered(lambda l: len(l.value_ids) > 1).mapped('attribute_id').ids to_currency = request.website.get_current_pricelist().currency_id attribute_value_ids = [] for variant in product.product_variant_ids: if to_currency != product.currency_id: - price = variant.currency_id.compute(variant.website_public_price, to_currency) + price = variant.currency_id.compute(variant.website_public_price, to_currency) / quantity else: - price = variant.website_public_price + price = variant.website_public_price / quantity visible_attribute_ids = [v.id for v in variant.attribute_value_ids if v.attribute_id.id in visible_attrs_ids] attribute_value_ids.append([variant.id, visible_attribute_ids, variant.website_price, price]) return attribute_value_ids diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 49f7399abcb..25e6cabb0a0 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -86,23 +86,30 @@ odoo.define('website_sale.website_sale', function (require) { $(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"); + }); }); } }); @@ -294,17 +301,18 @@ odoo.define('website_sale.website_sale', function (require) { $(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"); @@ -318,8 +326,10 @@ odoo.define('website_sale.website_sale', function (require) { if (variant_ids[k][3]-variant_ids[k][2]>0.01) { $default_price.closest('.oe_website_sale').addClass("discount"); $optional_price.closest('.oe_optional').show().css('text-decoration', 'line-through'); + $default_price.parent().removeClass('hidden'); } else { $optional_price.closest('.oe_optional').hide(); + $default_price.parent().addClass('hidden'); } product_id = variant_ids[k][0]; update_product_image(this, product_id); diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index a695837fd7a..8bba602c840 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -443,7 +443,8 @@