From 429f9b70af0e72f038bd8bf1ddbfe45f0fbc4117 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Mon, 8 Feb 2021 13:10:09 +0000 Subject: [PATCH] [IMP] website, website_sale: remove recently viewed products Before this commit recently viewed products included below the single product details were a specific snippet. After this commit recently viewed products has been removed and cross-product drop areas have been added to the product page. task-2453416 https://github.com/odoo/odoo/pull/65554 See https://github.com/odoo/upgrade/pull/2153 --- addons/website/views/snippets/snippets.xml | 1 - ...ntly_viewed.svg => s_dynamic_products.svg} | 0 .../src/js/website_sale_recently_viewed.js | 175 ------------------ .../src/xml/website_sale_recently_viewed.xml | 49 ----- .../website_sale/views/snippets/snippets.xml | 12 -- addons/website_sale/views/templates.xml | 6 - 6 files changed, 243 deletions(-) rename addons/website_sale/static/src/img/snippets_thumbs/{s_products_recently_viewed.svg => s_dynamic_products.svg} (100%) delete mode 100644 addons/website_sale/static/src/xml/website_sale_recently_viewed.xml diff --git a/addons/website/views/snippets/snippets.xml b/addons/website/views/snippets/snippets.xml index a5e4e2bba5e..73fd87c6c81 100644 --- a/addons/website/views/snippets/snippets.xml +++ b/addons/website/views/snippets/snippets.xml @@ -113,7 +113,6 @@ - diff --git a/addons/website_sale/static/src/img/snippets_thumbs/s_products_recently_viewed.svg b/addons/website_sale/static/src/img/snippets_thumbs/s_dynamic_products.svg similarity index 100% rename from addons/website_sale/static/src/img/snippets_thumbs/s_products_recently_viewed.svg rename to addons/website_sale/static/src/img/snippets_thumbs/s_dynamic_products.svg diff --git a/addons/website_sale/static/src/js/website_sale_recently_viewed.js b/addons/website_sale/static/src/js/website_sale_recently_viewed.js index ea9fedec840..cb34671ee69 100644 --- a/addons/website_sale/static/src/js/website_sale_recently_viewed.js +++ b/addons/website_sale/static/src/js/website_sale_recently_viewed.js @@ -1,182 +1,7 @@ odoo.define('website_sale.recently_viewed', function (require) { -var concurrency = require('web.concurrency'); -var config = require('web.config'); -var core = require('web.core'); var publicWidget = require('web.public.widget'); var utils = require('web.utils'); -var wSaleUtils = require('website_sale.utils'); - -var qweb = core.qweb; - -publicWidget.registry.productsRecentlyViewedSnippet = publicWidget.Widget.extend({ - selector: '.s_wsale_products_recently_viewed', - xmlDependencies: ['/website_sale/static/src/xml/website_sale_recently_viewed.xml'], - disabledInEditableMode: false, - read_events: { - 'click .js_add_cart': '_onAddToCart', - 'click .js_remove': '_onRemove', - }, - - /** - * @constructor - */ - init: function () { - this._super.apply(this, arguments); - this._dp = new concurrency.DropPrevious(); - this.uniqueId = _.uniqueId('o_carousel_recently_viewed_products_'); - this._onResizeChange = _.debounce(this._addCarousel, 100); - }, - /** - * @override - */ - start: function () { - this._dp.add(this._fetch()).then(this._render.bind(this)); - $(window).resize(() => { - this._onResizeChange(); - }); - return this._super.apply(this, arguments); - }, - /** - * @override - */ - destroy: function () { - this._super(...arguments); - this.$el.addClass('d-none'); - this.$el.find('.slider').html(''); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * @private - */ - _fetch: function () { - return this._rpc({ - route: '/shop/products/recently_viewed', - }).then(res => { - var products = res['products']; - - // In edit mode, if the current visitor has no recently viewed - // products, use demo data. - if (this.editableMode && (!products || !products.length)) { - return { - 'products': [{ - id: 0, - website_url: '#', - display_name: 'Product 1', - price: '$ 750.00', - }, { - id: 0, - website_url: '#', - display_name: 'Product 2', - price: '$ 750.00', - }, { - id: 0, - website_url: '#', - display_name: 'Product 3', - price: '$ 750.00', - }, { - id: 0, - website_url: '#', - display_name: 'Product 4', - price: '$ 750.00', - }], - }; - } - - return res; - }); - }, - /** - * @private - */ - _render: function (res) { - var products = res['products']; - var mobileProducts = [], webProducts = [], productsTemp = []; - _.each(products, function (product) { - if (productsTemp.length === 4) { - webProducts.push(productsTemp); - productsTemp = []; - } - productsTemp.push(product); - mobileProducts.push([product]); - }); - if (productsTemp.length) { - webProducts.push(productsTemp); - } - - this.mobileCarousel = $(qweb.render('website_sale.productsRecentlyViewed', { - uniqueId: this.uniqueId, - productFrame: 1, - productsGroups: mobileProducts, - })); - this.webCarousel = $(qweb.render('website_sale.productsRecentlyViewed', { - uniqueId: this.uniqueId, - productFrame: 4, - productsGroups: webProducts, - })); - this._addCarousel(); - this.$el.toggleClass('d-none', !(products && products.length)); - }, - /** - * Add the right carousel depending on screen size. - * @private - */ - _addCarousel: function () { - var carousel = config.device.size_class <= config.device.SIZES.SM ? this.mobileCarousel : this.webCarousel; - this.$('.slider').html(carousel).css('display', ''); // Removing display is kept for compatibility (it was hidden before) - }, - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * Add product to cart and reload the carousel. - * @private - * @param {Event} ev - */ - _onAddToCart: function (ev) { - var self = this; - var $card = $(ev.currentTarget).closest('.card'); - this._rpc({ - route: "/shop/cart/update_json", - params: { - product_id: $card.find('input[data-product-id]').data('product-id'), - add_qty: 1 - }, - }).then(function (data) { - wSaleUtils.updateCartNavBar(data); - var $navButton = $('header .o_wsale_my_cart').first(); - var fetch = self._fetch(); - var animation = wSaleUtils.animateClone($navButton, $(ev.currentTarget).parents('.o_carousel_product_card'), 25, 40); - Promise.all([fetch, animation]).then(function (values) { - self._render(values[0]); - }); - }); - }, - - /** - * Remove product from recently viewed products. - * @private - * @param {Event} ev - */ - _onRemove: function (ev) { - var self = this; - var $card = $(ev.currentTarget).closest('.card'); - this._rpc({ - route: "/shop/products/recently_viewed_delete", - params: { - product_id: $card.find('input[data-product-id]').data('product-id'), - }, - }).then(function (data) { - self._render(data); - }); - }, -}); publicWidget.registry.productsRecentlyViewedUpdate = publicWidget.Widget.extend({ selector: '#product_detail', diff --git a/addons/website_sale/static/src/xml/website_sale_recently_viewed.xml b/addons/website_sale/static/src/xml/website_sale_recently_viewed.xml deleted file mode 100644 index 34b9ec0ea5f..00000000000 --- a/addons/website_sale/static/src/xml/website_sale_recently_viewed.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - -