diff --git a/addons/website_sale/static/src/js/website_sale_utils.js b/addons/website_sale/static/src/js/website_sale_utils.js index fda9a75778b..7076ff9c7c9 100644 --- a/addons/website_sale/static/src/js/website_sale_utils.js +++ b/addons/website_sale/static/src/js/website_sale_utils.js @@ -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) { diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 9b1c32ca417..d608f4973d0 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -613,10 +613,7 @@ - - - - + diff --git a/addons/website_sale_comparison/views/website_sale_comparison_template.xml b/addons/website_sale_comparison/views/website_sale_comparison_template.xml index 07f0616c1d4..3889b05a148 100644 --- a/addons/website_sale_comparison/views/website_sale_comparison_template.xml +++ b/addons/website_sale_comparison/views/website_sale_comparison_template.xml @@ -8,13 +8,13 @@ - + - + diff --git a/addons/website_sale_wishlist/models/product_wishlist.py b/addons/website_sale_wishlist/models/product_wishlist.py index 54a31f5718e..4d90d79e076 100644 --- a/addons/website_sale_wishlist/models/product_wishlist.py +++ b/addons/website_sale_wishlist/models/product_wishlist.py @@ -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)]) diff --git a/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js b/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js index f3fa749f13f..47cdee788f8 100644 --- a/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js +++ b/addons/website_sale_wishlist/static/src/js/website_sale_wishlist.js @@ -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'; diff --git a/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml b/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml index db27cdc0e4e..a71545bbd11 100644 --- a/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml +++ b/addons/website_sale_wishlist/views/website_sale_wishlist_template.xml @@ -8,16 +8,18 @@ - + - + + - + - + + @@ -44,6 +46,9 @@ My Wishlist + + Add product to my cart but keep it in my wishlist + @@ -75,7 +80,6 @@ - Move to Cart Add to Cart