[MERGE] forward port branch 9.0 up to 34bc9b4983
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -288,17 +296,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");
|
||||
|
||||
@@ -311,9 +319,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];
|
||||
|
||||
@@ -371,7 +371,8 @@
|
||||
<h1 itemprop="name" t-field="product.name">Product Name</h1>
|
||||
<span itemprop="url" style="display:none;" t-esc="'/shop/product/%s' % slug(product)"/>
|
||||
|
||||
<form t-att-action="keep('/shop/cart/update')" class="js_add_cart_variants" t-att-data-attribute_value_ids="product.product_variant_ids.ids" method="POST">
|
||||
<t t-set="attribute_value_ids" t-value="get_attribute_value_ids(product)"/>
|
||||
<form t-att-action="keep('/shop/cart/update')" class="js_add_cart_variants" t-att-data-attribute_value_ids="attribute_value_ids" method="POST">
|
||||
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
|
||||
<div class="js_product">
|
||||
<t t-placeholder="select">
|
||||
|
||||
@@ -54,8 +54,16 @@ class WebsiteSaleOptions(WebsiteSale):
|
||||
to_currency = pricelist.currency_id
|
||||
compute_currency = lambda price: request.env['res.currency']._compute(from_currency, to_currency, price)
|
||||
product = request.env['product.product'].with_context(product_context).browse(int(product_id))
|
||||
main_product_attr_ids = self.get_attribute_value_ids(product)
|
||||
for variant in main_product_attr_ids:
|
||||
if variant[0] == product.id:
|
||||
# We indeed need a list of lists (even with only 1 element)
|
||||
main_product_attr_ids = [variant]
|
||||
break
|
||||
|
||||
return request.website._render("website_sale_options.modal", {
|
||||
'product': product,
|
||||
'compute_currency': compute_currency,
|
||||
'get_attribute_value_ids': self.get_attribute_value_ids,
|
||||
'main_product_attr_ids': main_product_attr_ids,
|
||||
})
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
.css_not_available.js_product > *:nth-child(5) > * {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.oe_striked_price {
|
||||
text-decoration: line-through;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ $('.oe_website_sale #add_to_cart, .oe_website_sale #products_grid .a-submit')
|
||||
var qty = $dom.find('input[name="add_qty"]').val();
|
||||
var product_ids = [product_id];
|
||||
var $products_dom = [];
|
||||
$modal.find(".js_add_cart_variants[data-attribute_value_ids]").each(function(){
|
||||
$("ul.js_add_cart_variants[data-attribute_value_ids]").each(function(){
|
||||
var $el = $(this);
|
||||
$products_dom.push($el);
|
||||
_.each($el.data("attribute_value_ids"), function (values) {
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="product_confirmation">
|
||||
<tr id="product_confirmation" class="js_product">
|
||||
<td width="100">
|
||||
<span t-field="product.image_medium" t-field-options='{"widget": "image" }'/>
|
||||
</td>
|
||||
@@ -55,14 +55,16 @@
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span t-attf-class="text-danger oe_default_price" style="text-decoration: line-through; white-space: nowrap;"
|
||||
<ul class="hidden js_add_cart_variants" t-att-data-attribute_value_ids="main_product_attr_ids"></ul>
|
||||
<div class="hidden oe_unchanged_value_ids" t-att-data-unchanged_value_ids="main_product_attr_ids[0][1]" ></div>
|
||||
<span t-attf-class="text-danger oe_default_price oe_striked_price {{ (compute_currency(product.lst_price) - product.price) < 0.01 and 'hidden' }}"
|
||||
t-field="product.lst_price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"from_currency": "product.currency_id",
|
||||
"display_currency": "website.currency_id"
|
||||
}'/>
|
||||
<span class="oe_price" style="white-space: nowrap;"
|
||||
<span class="oe_price product_id" style="white-space: nowrap;"
|
||||
t-att-data-product-id="product.id"
|
||||
t-field="product.price"
|
||||
t-field-options='{
|
||||
|
||||
Reference in New Issue
Block a user