You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
4.2 KiB
91 lines
4.2 KiB
/** @odoo-module **/
|
|
|
|
import VariantMixin from '@website_sale/js/sale_variant_mixin';
|
|
import publicWidget from "@web/legacy/js/public/public_widget";
|
|
import { session } from "@web/session";
|
|
import { jsonrpc } from "@web/core/network/rpc_service";
|
|
/**
|
|
* VariantMixin module for Odoo e-commerce platform.
|
|
* Overrides the _onChangeCombination method of the sale.VariantMixin module to add additional functionality.
|
|
* This mixin checks if the selected product variant is available or not and displays an appropriate message to the user.
|
|
*
|
|
* @module website_hide_variants.VariantMixin
|
|
* @requires sale.VariantMixin
|
|
* @requires web.core
|
|
* @requires web.rpc
|
|
* @augments sale.VariantMixin
|
|
*/
|
|
VariantMixin._onChangeCombinationVariants = async function (ev, $parent, combination) {
|
|
var count = false
|
|
// Check if the selected combination has a valid product ID
|
|
var product = combination.product_id
|
|
if (combination.product_id) {
|
|
await jsonrpc('/variants/'+combination.product_id, {}).then(function(res) {
|
|
// Check if the product is marked as "website_hide_variants"
|
|
if (res) {
|
|
// Disable the combination and display an appropriate message to the user
|
|
combination.is_combination_possible = false
|
|
count = true
|
|
}
|
|
});
|
|
}
|
|
// Update the product variant information
|
|
var $price = $parent.find(".oe_price:first .oe_currency_value");
|
|
var $default_price = $parent.find(".oe_default_price:first .oe_currency_value");
|
|
var $optional_price = $parent.find(".oe_optional:first .oe_currency_value");
|
|
$price.text(this._priceToStr(combination.price));
|
|
$default_price.text(this._priceToStr(combination.list_price));
|
|
var isCombinationPossible = true;
|
|
if (combination.is_combination_possible !== "undefined") {
|
|
isCombinationPossible = combination.is_combination_possible;
|
|
}
|
|
this._toggleDisable($parent, isCombinationPossible);
|
|
if (combination.has_discounted_price) {
|
|
$default_price.closest('.oe_website_sale').addClass("discount");
|
|
$optional_price.closest('.oe_optional').removeClass('d-none').css('text-decoration', 'line-through');
|
|
$default_price.parent().removeClass('d-none');
|
|
} else {
|
|
$default_price.closest('.oe_website_sale').removeClass("discount");
|
|
$optional_price.closest('.oe_optional').addClass('d-none');
|
|
$default_price.parent().addClass('d-none');
|
|
}
|
|
var rootComponentSelectors = [
|
|
'tr.js_product',
|
|
'.oe_website_sale',
|
|
'.o_product_configurator'
|
|
];
|
|
if (!combination.product_id ||
|
|
!this.last_product_id ||
|
|
combination.product_id !== this.last_product_id) {
|
|
this.last_product_id = combination.product_id;
|
|
this._updateProductImage(
|
|
$parent.closest(rootComponentSelectors.join(', ')),
|
|
combination.display_image,
|
|
combination.product_id,
|
|
combination.product_template_id,
|
|
combination.carousel,
|
|
isCombinationPossible
|
|
);
|
|
}
|
|
$parent.find('.product_id').first().val(combination.product_id || 0).trigger('change');
|
|
$parent.find('.product_display_name').first().text(combination.display_name);
|
|
$parent.find('.js_raw_price').first().text(combination.price).trigger('change');
|
|
this.handleCustomValues($(ev.target));
|
|
// Display appropriate message to the user based on the availability of the selected variant
|
|
if (count) {
|
|
$('.css_not_available_msg')[0].innerText = "This Product is Out-of-stock."
|
|
} else {
|
|
$('.css_not_available_msg')[0].innerText = "This combination does not exist."
|
|
}
|
|
};
|
|
publicWidget.registry.WebsiteSale.include({
|
|
/**
|
|
* Adds the stock checking to the regular _onChangeCombination method
|
|
* @override
|
|
*/
|
|
_onChangeCombination: function () {
|
|
this._super.apply(this, arguments);
|
|
VariantMixin._onChangeCombinationVariants.apply(this, arguments);
|
|
},
|
|
});
|
|
export default VariantMixin;
|