Skip to content

Commit

Permalink
[FIX] sale, sale_management, website_sale: configurator option modal …
Browse files Browse the repository at this point in the history
…change variant

Part 1: Backend
Changing an option's variant now change the product name and the image

Part 2: Front end
The behavior is the same as in the backend.

For that part though, there is a huge design problem:
the modal dialog has the class .oe_website_sale, so the widget website_sale
reacts to events triggered in the modal.

It is understandable given the history of the module, but a proper refactoring
that will implement inheriting of business behaviors through OdooClass extension/overrides
is necessary in master

OPW 1938217
  • Loading branch information
kebeclibre committed Feb 20, 2019
1 parent 43ce839 commit aa1e26f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
8 changes: 5 additions & 3 deletions addons/sale/static/src/js/product_configurator_mixin.js
Expand Up @@ -183,7 +183,7 @@ var ProductConfiguratorMixin = {
*/ */
triggerVariantChange: function ($container) { triggerVariantChange: function ($container) {
var self = this; var self = this;
$container.find('ul[data-attribute_exclusions]').trigger('change'); $container.find('ul[data-attribute_exclusions]').trigger('change', {$container: $container});
$container.find('input.js_variant_change:checked, select.js_variant_change').each(function () { $container.find('input.js_variant_change:checked, select.js_variant_change').each(function () {
self.handleCustomValues($(this)); self.handleCustomValues($(this));
}); });
Expand Down Expand Up @@ -559,14 +559,16 @@ var ProductConfiguratorMixin = {
_updateProductImage: function ($productContainer, productId, productTemplateId) { _updateProductImage: function ($productContainer, productId, productTemplateId) {
var model = productId ? 'product.product' : 'product.template'; var model = productId ? 'product.product' : 'product.template';
var modelId = productId || productTemplateId; var modelId = productId || productTemplateId;
var imageSrc = '/web/image/{0}/{1}/image' var imageUrl = '/web/image/{0}/{1}/' + (this._productImageField ? this._productImageField : 'image');
var imageSrc = imageUrl
.replace("{0}", model) .replace("{0}", model)
.replace("{1}", modelId); .replace("{1}", modelId);


var imagesSelectors = [ var imagesSelectors = [
'span[data-oe-model^="product."][data-oe-type="image"] img:first', 'span[data-oe-model^="product."][data-oe-type="image"] img:first',
'img.product_detail_img', 'img.product_detail_img',
'span.variant_image img' 'span.variant_image img',
'img.variant_image',
]; ];


var $img = $productContainer.find(imagesSelectors.join(', ')); var $img = $productContainer.find(imagesSelectors.join(', '));
Expand Down
12 changes: 11 additions & 1 deletion addons/sale/static/src/js/product_configurator_modal.js
Expand Up @@ -69,9 +69,9 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi
this.dialogClass = 'oe_optional_products_modal' + (params.isWebsite ? ' oe_website_sale' : ''); this.dialogClass = 'oe_optional_products_modal' + (params.isWebsite ? ' oe_website_sale' : '');


if (this.isWebsite) { if (this.isWebsite) {
delete this.events['change [data-attribute_exclusions]'];
delete this.events['click button.js_add_cart_json']; delete this.events['click button.js_add_cart_json'];
} }
this._productImageField = 'image_medium';
}, },
/** /**
* @override * @override
Expand Down Expand Up @@ -440,7 +440,17 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi
delete optionalProductsMap[optionId]; delete optionalProductsMap[optionId];
} }
}, },
/**
* @override
*/
_onChangeCombination:function (ev, $parent, combination) {
$parent
.find('.td-product_name .product-name')
.first()
.text(combination.display_name);


ProductConfiguratorMixin._onChangeCombination.apply(this, arguments);
},
/** /**
* When the quantity of the root product is updated, we need to update * When the quantity of the root product is updated, we need to update
* the quantity of all the selected optional products. * the quantity of all the selected optional products.
Expand Down
Expand Up @@ -3,6 +3,8 @@ odoo.define('sale.sale_product_configurator_advanced_tour', function (require) {


var tour = require('web_tour.tour'); var tour = require('web_tour.tour');


var optionVariantImage;

tour.register('sale_product_configurator_advanced_tour', { tour.register('sale_product_configurator_advanced_tour', {
url: "/web", url: "/web",
test: true, test: true,
Expand Down Expand Up @@ -95,6 +97,25 @@ tour.register('sale_product_configurator_advanced_tour', {
trigger: '.main_product div:contains("PA8: PAV1")', trigger: '.main_product div:contains("PA8: PAV1")',
extra_trigger: '.oe_optional_products_modal', extra_trigger: '.oe_optional_products_modal',
run: function () {} //check run: function () {} //check
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (Steel)")',
run: function () {
optionVariantImage = $('.oe_optional_products_modal .js_product:eq(1) img.variant_image').attr('src');
}
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) input[data-value_name="Aluminium"]',
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (Aluminium)")',
run: function () {
var newVariantImage = $('.oe_optional_products_modal .js_product:eq(1) img.variant_image').attr('src');
if (newVariantImage !== optionVariantImage) {
$('<p>').text('image variant option src changed').insertAfter('.oe_optional_products_modal .js_product:eq(1) .product-name');
}

}
}, {
extra_trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("image variant option src changed")',
trigger: '.oe_optional_products_modal .js_product:eq(1) input[data-value_name="Steel"]',
}, { }, {
trigger: 'button span:contains(Confirm)', trigger: 'button span:contains(Confirm)',
extra_trigger: '.oe_optional_products_modal', extra_trigger: '.oe_optional_products_modal',
Expand Down
16 changes: 16 additions & 0 deletions addons/website_sale/static/src/js/website_sale.js
Expand Up @@ -152,6 +152,8 @@ sAnimations.registry.WebsiteSale = sAnimations.Class.extend(ProductConfiguratorM
'change #shipping_use_same': '_onChangeShippingUseSame', 'change #shipping_use_same': '_onChangeShippingUseSame',
'click .toggle_summary': '_onToggleSummary', 'click .toggle_summary': '_onToggleSummary',
'click input.js_product_change': 'onChangeVariant', 'click input.js_product_change': 'onChangeVariant',
// dirty fix: prevent options modal events to be triggered and bubbled
'change oe_optional_products_modal [data-attribute_exclusions]': 'onChangeVariant',
}, },


/** /**
Expand Down Expand Up @@ -589,6 +591,20 @@ sAnimations.registry.WebsiteSale = sAnimations.Class.extend(ProductConfiguratorM
_onChangeShippingUseSame: function (ev) { _onChangeShippingUseSame: function (ev) {
$('.ship_to_other').toggle(!$(ev.currentTarget).prop('checked')); $('.ship_to_other').toggle(!$(ev.currentTarget).prop('checked'));
}, },
/**
* @override
*
* Dirty fix: prevent options modal events to be triggered and bubbled
*/
onChangeVariant: function (ev, data) {
var $originPath = ev.originalEvent && Array.isArray(ev.originalEvent.path) ? $(ev.originalEvent.path) : $();
var $container = data && data.$container ? data.$container : $();
if ($originPath.add($container).hasClass('oe_optional_products_modal')) {
ev.stopPropagation();
return;
}
return ProductConfiguratorMixin.onChangeVariant.apply(this, arguments);
},
/** /**
* @private * @private
*/ */
Expand Down
Expand Up @@ -4,6 +4,8 @@ odoo.define("website_sale.tour_shop_custom_attribute_value", function (require)
var tour = require("web_tour.tour"); var tour = require("web_tour.tour");
var base = require("web_editor.base"); var base = require("web_editor.base");


var optionVariantImage;

tour.register("shop_custom_attribute_value", { tour.register("shop_custom_attribute_value", {
url: "/shop", url: "/shop",
test: true, test: true,
Expand Down Expand Up @@ -34,6 +36,24 @@ odoo.define("website_sale.tour_shop_custom_attribute_value", function (require)
}, { }, {
trigger: 'span.oe_price span:contains(600)', trigger: 'span.oe_price span:contains(600)',
run: function (){}, // check run: function (){}, // check
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (Steel)")',
run: function () {
optionVariantImage = $('.oe_optional_products_modal .js_product:eq(1) img.variant_image').attr('src');
}
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) input[data-value_name="Aluminium"]',
}, {
trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("Conference Chair (Aluminium)")',
run: function () {
var newVariantImage = $('.oe_optional_products_modal .js_product:eq(1) img.variant_image').attr('src');
if (newVariantImage !== optionVariantImage) {
$('<p>').text('image variant option src changed').insertAfter('.oe_optional_products_modal .js_product:eq(1) .product-name');
}
}
}, {
extra_trigger: '.oe_optional_products_modal .js_product:eq(1) div:contains("image variant option src changed")',
trigger: '.oe_optional_products_modal .js_product:eq(1) input[data-value_name="Steel"]',
}, { }, {
trigger: 'li.js_attribute_value span:contains(Aluminium)', trigger: 'li.js_attribute_value span:contains(Aluminium)',
extra_trigger: '.oe_optional_products_modal', extra_trigger: '.oe_optional_products_modal',
Expand Down

0 comments on commit aa1e26f

Please sign in to comment.