summaryrefslogtreecommitdiff
path: root/addons/website_sale/static
diff options
context:
space:
mode:
authorxO-Tx <mou@odoo.com>2020-10-28 17:33:17 +0000
committerJeremy Kersten <jke@odoo.com>2020-11-03 15:01:20 +0000
commit5064bfa85dcf35410ed0e0053b675debf6883484 (patch)
treec365e2b10b109d2d23bbf83e646a1bb3ae0526ef /addons/website_sale/static
parenta4b358a76ece2a3fb66cbdb99c7685613cf8c25a (diff)
[IMP] website_sale: set product variants from search filter
In the shop when the product page is loaded, the variants are now selected from search attributes if filter is applied. Since we have a hash containing variants unique id in product url, we can apply variants from search filter attributes in url instead of default ones. + fix filter style Now: When you filter in /shop the product on color black, and click on the product desk (first variant in white), you are now redirected to the product with color black selected This commit closes #47117 and is related to #22982 task-2369420 closes odoo/odoo#60929 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/website_sale/static')
-rw-r--r--addons/website_sale/static/src/js/website_sale.js34
1 files changed, 27 insertions, 7 deletions
diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js
index 20c17679cf9..89bce50f005 100644
--- a/addons/website_sale/static/src/js/website_sale.js
+++ b/addons/website_sale/static/src/js/website_sale.js
@@ -195,11 +195,10 @@ publicWidget.registry.WebsiteSale = publicWidget.Widget.extend(VariantMixin, {
/**
* @override
*/
- start: function () {
- var self = this;
- var def = this._super.apply(this, arguments);
+ start() {
+ const def = this._super(...arguments);
- this._applyHash();
+ this._applyHashFromSearch();
_.each(this.$('div.js_product'), function (product) {
$('input.js_product_change', product).first().trigger('change');
@@ -218,9 +217,9 @@ publicWidget.registry.WebsiteSale = publicWidget.Widget.extend(VariantMixin, {
this._startZoom();
- window.addEventListener('hashchange', function (e) {
- self._applyHash();
- self.triggerVariantChange($(self.el));
+ window.addEventListener('hashchange', () => {
+ this._applyHash();
+ this.triggerVariantChange(this.$el);
});
return def;
@@ -718,6 +717,27 @@ publicWidget.registry.WebsiteSale = publicWidget.Widget.extend(VariantMixin, {
$('.toggle_summary_div').toggleClass('d-none');
$('.toggle_summary_div').removeClass('d-xl-block');
},
+ /**
+ * @private
+ */
+ _applyHashFromSearch() {
+ const params = $.deparam(window.location.search.slice(1));
+ if (params.attrib) {
+ const dataValueIds = [];
+ for (const attrib of [].concat(params.attrib)) {
+ const attribSplit = attrib.split('-');
+ const attribValueSelector = `.js_variant_change[name="ptal-${attribSplit[0]}"][value="${attribSplit[1]}"]`;
+ const attribValue = this.el.querySelector(attribValueSelector);
+ if (attribValue !== null) {
+ dataValueIds.push(attribValue.dataset.value_id);
+ }
+ }
+ if (dataValueIds.length) {
+ history.replaceState(undefined, undefined, `#attr=${dataValueIds.join(',')}`);
+ }
+ }
+ this._applyHash();
+ },
});
publicWidget.registry.WebsiteSaleLayout = publicWidget.Widget.extend({