[IMP] website_sale_wishlist: improve wishlist after first users test

- Update Cart Quantity when 'add to cart'
- Change usability for b2b/b2c add/move to cart
- Disable 'add to wishlist' if already in wish list
- Wait the commit of 'Move to cart' of the last item
  before the redirect to avoid to get a fake empty cart.
- Reset red notification after a small delay
- Fix 'list of variants' optional feature (broken by commit 045a859)
- Adjust animation to match cart/wishlist
- Fix button cart / wishlist / comparison order
- ...

Courtesy of @adr-odoo for testing
This commit is contained in:
Jeremy Kersten
2017-04-05 17:27:15 +02:00
parent 414bfa132b
commit ff8f50d3b3
6 changed files with 61 additions and 26 deletions
@@ -4,6 +4,8 @@ odoo.define('website_sale.utils', function (require) {
var animate_clone = function(cart, $elem, offset_top, offset_left) {
cart.find('.o_animate_blink').addClass('o_red_highlight o_shadow_animation').delay(500).queue(function(){
$(this).removeClass("o_shadow_animation").dequeue();
}).delay(2000).queue(function(){
$(this).removeClass("o_red_highlight").dequeue();
});
var imgtodrag = $elem.find('img').eq(0);
if (imgtodrag.length) {
+1 -4
View File
@@ -613,10 +613,7 @@
<template id="product_variants" inherit_id="website_sale.product" active="False" customize_show="True" name="List View of Variants">
<xpath expr="//t[@t-placeholder='select']" position="replace">
<input type="hidden" t-if="len(product.product_variant_ids) == 1" name="product_id" t-att-value="product.product_variant_id.id"/>
<t t-call="website_sale.variants">
<t t-set="ul_class" t-value="'nav-stacked'"/>
</t>
<input type="hidden" t-if="len(product.product_variant_ids) == 1" class="product_id" name="product_id" t-att-value="product.product_variant_id.id"/>
<t t-if="len(product.product_variant_ids) &gt; 1">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="variant_id">
<input type="radio" name="product_id" class="js_product_change" t-att-checked="'checked' if variant_id_index == 0 else None" t-att-value="variant_id.id" t-att-data-lst_price="variant_id.lst_price" t-att-data-price="variant_id.price"/>
@@ -8,13 +8,13 @@
</xpath>
</template>
<template id="add_to_compare" inherit_id="website_sale.products_item" active="True" customize_show="True" name="Comparison List">
<template id="add_to_compare" inherit_id="website_sale.products_item" active="True" customize_show="True" name="Comparison List" priority="22">
<xpath expr="//div[@class='product_price']" position="inside">
<a class="hidden-xs btn btn-default btn-xs o_add_compare" title="Compare" t-att-data-product-product-id="product.product_variant_ids[0].id" data-action="o_comparelist"><span class="fa fa-exchange"></span></a>
</xpath>
</template>
<template id="product_add_to_compare" name='Add to comparison in product page' inherit_id="website_sale.product">
<template id="product_add_to_compare" name='Add to comparison in product page' inherit_id="website_sale.product" priority="8">
<xpath expr="//a[@id='add_to_cart']" position="after">
<t t-if="product.env.ref('website_sale_comparison.add_to_compare').active">
<a class="hidden-xs btn btn-default btn-lg mt8 o_add_compare_dyn" title="Compare" t-att-data-product-product-id="product.product_variant_ids[0].id" data-action="o_comparelist"><span class="fa fa-exchange"></span></a>
@@ -33,3 +33,9 @@ class ProductWishlist(models.Model):
'product_id': product_id,
})
return wish
class ResPartner(models.Model):
_inherit = 'res.partner'
wishlist_ids = fields.One2many('product.wishlist', 'partner_id', string='Wishlist', domain=[('active', '=', True)])
@@ -32,27 +32,40 @@ var ProductWishlist = Widget.extend({
});
if ($('.wishlist-section').length) {
$('.wishlist-section a.o_wish_rm').on('click', function (e){ self.wishlist_rm(e); });
$('.wishlist-section a.o_wish_add').on('click', function (e){ self.wishlist_add(e); });
$('.wishlist-section a.o_wish_mv').on('click', function (e){ self.wishlist_mv(e); });
$('.wishlist-section a.o_wish_rm').on('click', function (e){ self.wishlist_rm(e, false); });
$('.wishlist-section a.o_wish_add').on('click', function (e){ self.wishlist_add_or_mv(e); });
}
$('.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('.product_id').first();
var $el = $parent.find("[data-action='o_wishlist']");
if (!_.contains(self.wishlist_product_ids, parseInt($product_id.val(), 10))) {
$el.prop("disabled", false).removeClass('disabled').removeAttr('disabled');
}
else {
$el.prop("disabled", true).addClass('disabled').attr('disabled', 'disabled');
}
});
},
add_new_products:function($el, e){
var self = this;
var product_id = $el.data('product-product-id');
if (e.currentTarget.classList.contains('o_add_wishlist_dyn')) {
product_id = parseInt($el.parent().find('.product_id').val());
}
if (odoo.session_info.is_website_user){
this.warning_not_logged();
} else {
var product_id = $el.data('product-product-id');
if (e.currentTarget.classList.contains('o_add_wishlist_dyn')) {
product_id = parseInt($el.parent().find('.product_id').val());
}
if (!_.contains(self.wishlist_product_ids, product_id)) {
return ajax.jsonRpc('/shop/wishlist/add', 'call', {
'product_id': product_id
}).then(function () {
self.wishlist_product_ids.push(product_id);
self.update_wishlist_view();
website_sale_utils.animate_clone($('#my_wish'), $el.closest('form'), 10, 10);
website_sale_utils.animate_clone($('#my_wish'), $el.closest('form'), 25, 40);
$el.prop("disabled", true).addClass('disabled');
});
}
}
@@ -78,29 +91,37 @@ var ProductWishlist = Widget.extend({
$('#my_wish').hide();
}
},
wishlist_rm: function(e){
wishlist_rm: function(e, deferred_redirect){
var tr = $(e.currentTarget).parents('tr');
var wish = tr.data('wish-id');
var product = tr.data('product-id');
var self = this;
new Model('product.wishlist')
.call('write', [[wish], { active: false }, base.get_context()])
.then(function(){
$(tr).hide();
});
this.wishlist_product_ids = _.without(this.wishlist_product_ids, product);
if (this.wishlist_product_ids.length === 0) {
this.redirect_no_wish();
deferred_redirect = deferred_redirect ? deferred_redirect : $.Deferred();
deferred_redirect.then(function() {
self.redirect_no_wish();
});
}
this.update_wishlist_view();
},
wishlist_add_or_mv: function(e){
return $('#b2b_wish').is(':checked') ? this.wishlist_add(e) : this.wishlist_mv(e);
},
wishlist_add: function(e){
var tr = $(e.currentTarget).parents('tr');
var product = tr.data('product-id');
// can be hidden if empty
$('#my_cart').removeClass('hidden');
website_sale_utils.animate_clone($('#my_cart'), tr, 0, 0);
website_sale_utils.animate_clone($('#my_cart'), tr, 25, 40);
this.add_to_cart(product, tr.find('qty').val() || 1);
},
wishlist_mv: function(e){
@@ -108,15 +129,20 @@ var ProductWishlist = Widget.extend({
var product = tr.data('product-id');
$('#my_cart').removeClass('hidden');
website_sale_utils.animate_clone($('#my_cart'), tr, 0, 0);
this.add_to_cart(product, tr.find('qty').val() || 1);
this.wishlist_rm(e);
website_sale_utils.animate_clone($('#my_cart'), tr, 25, 40);
var adding_deffered = this.add_to_cart(product, tr.find('qty').val() || 1);
this.wishlist_rm(e, adding_deffered);
},
add_to_cart: function(product_id, qty_id) {
ajax.jsonRpc("/shop/cart/update_json", 'call', {
var add_to_cart = ajax.jsonRpc("/shop/cart/update_json", 'call', {
'product_id': parseInt(product_id, 10),
'add_qty': parseInt(qty_id, 10)
});
add_to_cart.then(function(resp) {
$('.my_cart_quantity').text(resp.cart_quantity || '* 1');
});
return add_to_cart;
},
redirect_no_wish: function() {
window.location = '/shop/cart';
@@ -8,16 +8,18 @@
</xpath>
</template>
<template id="add_to_wishlist" inherit_id="website_sale.products_item" active="True" customize_show="True" name="Wishlist" priority="10">
<template id="add_to_wishlist" inherit_id="website_sale.products_item" active="True" customize_show="True" name="Wishlist" priority="20">
<xpath expr="//div[@class='product_price']" position="inside">
<a class="btn btn-default btn-xs o_add_wishlist" title="Add to Wishlist" t-att-data-product-product-id="product.product_variant_ids[0].id" data-action="o_wishlist"><span class="fa fa-heart"></span></a>
<t t-set="in_wish" t-value="product.product_variant_ids[0] in request.env.user.partner_id.wishlist_ids.mapped('product_id')"/>
<a class="btn btn-default btn-xs o_add_wishlist" t-att-disabled='in_wish or None' title="Add to Wishlist" t-att-data-product-product-id="product.product_variant_ids[0].id" data-action="o_wishlist"><span class="fa fa-heart"></span></a>
</xpath>
</template>
<template id="product_add_to_wishlist" name='Add to wishlist in product page' inherit_id="website_sale.product" priority="10">
<template id="product_add_to_wishlist" name='Add to wishlist in product page' inherit_id="website_sale.product" priority="20">
<xpath expr="//a[@id='add_to_cart']" position="after">
<t t-if="product.env.ref('website_sale_wishlist.add_to_wishlist').active">
<a class="btn btn-default btn-lg mt8 o_add_wishlist_dyn" title="Add to Wishlist" t-att-data-product-product-id="product.product_variant_ids[0].id" data-action="o_wishlist"><span class="fa fa-heart"></span></a>
<t t-set="in_wish" t-value="product.product_variant_ids[0] in request.env.user.partner_id.wishlist_ids.mapped('product_id')"/>
<a class="btn btn-default btn-lg mt8 o_add_wishlist_dyn" t-att-disabled='in_wish or None' title="Add to Wishlist" t-att-data-product-product-id="product.product_variant_ids[0].id" data-action="o_wishlist"><span class="fa fa-heart"></span></a>
</t>
</xpath>
</template>
@@ -44,6 +46,9 @@
<div class="container oe_website_sale">
<section class="container wishlist-section">
<h3>My Wishlist</h3>
<div class="checkbox">
<label class='text-muted'><input type="checkbox" id='b2b_wish' value="1" />Add product to my cart but keep it in my wishlist</label>
</div>
<table class="table table-bordered table-striped table-hover text-center mt16 table-comparator" id="o_comparelist_table">
<body>
<t t-foreach="wishes" t-as="wish">
@@ -75,7 +80,6 @@
</td>
<td class='text-center td-wish-btn'>
<input name="product_id" t-att-value="wish.product_id.id" type="hidden"/>
<a class="btn btn-primary btn-block o_wish_mv mb4">Move <span class='hidden-xs'>to Cart</span></a>
<a class="btn btn-default btn-block o_wish_add mb4" >Add <span class='hidden-xs'>to Cart</span></a>
</td>
</tr>