diff options
| author | fja-odoo <fja@odoo.com> | 2019-08-21 16:40:10 +0000 |
|---|---|---|
| committer | fja-odoo <fja@odoo.com> | 2019-09-16 09:38:53 +0000 |
| commit | e33172e83210a5e0044a6fb92e315b84deefc440 (patch) | |
| tree | 96edafcf0a9f2807bfe011fcfae414978f0f88a1 /addons/website/static/src | |
| parent | 1bc4c1697f33c70927f204ffbd38d1e0ad9cba07 (diff) | |
[IMP] website_sale, *: keep track of products viewed
*= website, website_livechat, website_rating
///// Tracking Product /////
Now when a user browse products in eCommerce, we keep track of the
products he looked at. We use the website_visitor
to store the products viewed. A cookie is added with a TTl of 30 min it
will prevent the RPC for that time. We track the page only if the
product view is tracked.
The recently viewed products are displayed as a snippet but also
with the customize option in product pages of website_sale.
Products that are in cart will not be returned as recently viewed.
It is possible to add a recently viewed product to the cart directly
from the carousel, it will not redirect to the cart. If we are on the
cart page, the product is displayed in the cart.
The Visitor page in website now references products viewed
///// Tracking Page /////
Feature to track a view was remove in: https://github.com/odoo/enterprise/pull/4834
That feature is now reintroduced and will use website_track instead of
leads to be stored.
The track field is now on the view instead of the page.
url field is added to website.track, it will store the url for pages and
views
The Visitor page in website now references urls viewed
Add some tests
task-1984575
closes odoo/odoo#35810
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/website/static/src')
| -rw-r--r-- | addons/website/static/src/img/snippets_thumbs/s_products_recently_viewed.png | bin | 0 -> 833 bytes | |||
| -rw-r--r-- | addons/website/static/src/js/set_view_track.js | 89 | ||||
| -rw-r--r-- | addons/website/static/src/xml/track_page.xml | 15 |
3 files changed, 104 insertions, 0 deletions
diff --git a/addons/website/static/src/img/snippets_thumbs/s_products_recently_viewed.png b/addons/website/static/src/img/snippets_thumbs/s_products_recently_viewed.png Binary files differnew file mode 100644 index 00000000000..c55ad28b628 --- /dev/null +++ b/addons/website/static/src/img/snippets_thumbs/s_products_recently_viewed.png diff --git a/addons/website/static/src/js/set_view_track.js b/addons/website/static/src/js/set_view_track.js new file mode 100644 index 00000000000..d94fcddfffd --- /dev/null +++ b/addons/website/static/src/js/set_view_track.js @@ -0,0 +1,89 @@ +odoo.define('website.set_view_track', function (require) { +"use strict"; + +var CustomizeMenu = require('website.customizeMenu'); +var Widget = require('web.Widget'); + +var TrackPage = Widget.extend({ + template: 'website.track_page', + xmlDependencies: ['/website/static/src/xml/track_page.xml'], + events: { + 'change #switch-track-page': '_onTrackChange', + }, + + /** + * @override + */ + start: function () { + this.$input = this.$('#switch-track-page'); + this._isTracked().then((data) => { + if (data[0]['track']) { + this.track = true; + this.$input.attr('checked', 'checked'); + } else { + this.track = false; + } + }); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + */ + _isTracked: function (val) { + var viewid = $('html').data('viewid'); + if (!viewid) { + return Promise.reject(); + } else { + return this._rpc({ + model: 'ir.ui.view', + method: 'read', + args: [[viewid], ['track']], + }); + } + }, + /** + * @private + */ + _onTrackChange: function (ev) { + var checkboxValue = this.$input.is(':checked'); + if (checkboxValue !== this.track) { + this.track = checkboxValue; + this._trackPage(checkboxValue); + } + }, + /** + * @private + */ + _trackPage: function (val) { + var viewid = $('html').data('viewid'); + if (!viewid) { + return Promise.reject(); + } else { + return this._rpc({ + model: 'ir.ui.view', + method: 'write', + args: [[viewid], {track: val}], + }); + } + }, +}); + +CustomizeMenu.include({ + _loadCustomizeOptions: function () { + var self = this; + var def = this._super.apply(this, arguments); + return def.then(function () { + if (!self.__trackpageLoaded) { + self.__trackpageLoaded = true; + self.trackPage = new TrackPage(self); + self.trackPage.appendTo(self.$el.children('.dropdown-menu')); + } + }); + }, +}); + +}); diff --git a/addons/website/static/src/xml/track_page.xml b/addons/website/static/src/xml/track_page.xml new file mode 100644 index 00000000000..11311156ca7 --- /dev/null +++ b/addons/website/static/src/xml/track_page.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<templates id="template" xml:space="preserve"> + + <t t-name="website.track_page"> + <div role="separator" class="dropdown-divider"/> + <a href="#" name="switch-track-page" class="dropdown-item" role="menuitem"> + <label class="o_switch" for="switch-track-page"> + <input id="switch-track-page" type="checkbox"/> + <span/> + Track visitor + </label> + </a> + </t> + +</templates> |
