[FIX] website,website_sale: Dynamic products isn't visible if category deleted
Issue - Install "Ecommerce" app - Go to 'Shop' page and edit it - Add a "Dynamic Products" block - Click on it to edit it : - Select any template - Select `Desks` as product category - Save - Go to "Website -> Configuration -> eCommerce Categories" - Delete the "Desks" category - Go back to Shop page Error : "Record does not exist or has been deleted". Cause The search domain is looking for child categories of dataset.productCategoryId (who does not exist anymore in the above case). `child_of` do a browse() to fetch the records, and therefore generate an error if category not found. Solution Check if dataset.productCategoryId exist before updating domain. opw-2416231 closes odoo/odoo#64157 X-original-commit: 0de069b8ca9fb005ba5b076984f5677de25889ee Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com> Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
@@ -94,14 +94,14 @@ const DynamicSnippet = publicWidget.Widget.extend({
|
||||
* domain if needed.
|
||||
* @private
|
||||
*/
|
||||
_getSearchDomain: function () {
|
||||
_getSearchDomain: async function () {
|
||||
return [];
|
||||
},
|
||||
/**
|
||||
* Fetches the data.
|
||||
* @private
|
||||
*/
|
||||
_fetchData: function () {
|
||||
_fetchData: async function () {
|
||||
if (this._isConfigComplete()) {
|
||||
return this._rpc(
|
||||
{
|
||||
@@ -110,7 +110,7 @@ const DynamicSnippet = publicWidget.Widget.extend({
|
||||
'filter_id': parseInt(this.$el.get(0).dataset.filterId),
|
||||
'template_key': this.$el.get(0).dataset.templateKey,
|
||||
'limit': parseInt(this.$el.get(0).dataset.numberOfRecords),
|
||||
'search_domain': this._getSearchDomain()
|
||||
'search_domain': await this._getSearchDomain()
|
||||
},
|
||||
})
|
||||
.then(
|
||||
|
||||
@@ -13,13 +13,25 @@ const DynamicSnippetProducts = DynamicSnippetCarousel.extend({
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check product category exist.
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
_checkCategoryExist: async function (productCategoryId) {
|
||||
return this._rpc({
|
||||
model: 'product.public.category',
|
||||
method: 'search_count',
|
||||
args: [[['id', '=', productCategoryId]]],
|
||||
}).then(nb => nb > 0);
|
||||
},
|
||||
/**
|
||||
* Method to be overridden in child components if additional configuration elements
|
||||
* are required in order to fetch data.
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_isConfigComplete: function() {
|
||||
_isConfigComplete: function () {
|
||||
return this._super.apply(this, arguments) && this.$el.get(0).dataset.productCategoryId !== undefined;
|
||||
},
|
||||
/**
|
||||
@@ -28,9 +40,15 @@ const DynamicSnippetProducts = DynamicSnippetCarousel.extend({
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_getSearchDomain: function () {
|
||||
const searchDomain = this._super.apply(this, arguments);
|
||||
searchDomain.push(['public_categ_ids', 'child_of', parseInt(this.$el.get(0).dataset.productCategoryId)]);
|
||||
_getSearchDomain: async function () {
|
||||
const searchDomain = await this._super.apply(this, arguments);
|
||||
const productCategoryId = parseInt(this.$el.get(0).dataset.productCategoryId);
|
||||
const categoryExist = await this._checkCategoryExist(productCategoryId);
|
||||
if (categoryExist) {
|
||||
searchDomain.push(['public_categ_ids', 'child_of', productCategoryId]);
|
||||
} else {
|
||||
searchDomain.push([0, '=', 1]);
|
||||
}
|
||||
return searchDomain;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user