[FIX] website_sale: improve the speed of /shop/cart/update_json

Before this commit, a lot of `/shop/cart/update_json` wrongly requested
to re-rendender cart templates.

Now, calls to `/shop/cart/update_json` will specify if they needs the
updated cart templates or not.

Part-of: odoo/odoo#133990
This commit is contained in:
Valentin Chevalier
2023-09-15 20:34:28 +00:00
committed by Victor Feyens
parent d84e570630
commit 95bb1c906b
5 changed files with 14 additions and 5 deletions
@@ -207,7 +207,8 @@ export const WebsiteSale = publicWidget.Widget.extend(VariantMixin, cartHandlerM
params: {
line_id: line_id,
product_id: parseInt($input.data('product-id'), 10),
set_qty: value
set_qty: value,
display: true,
},
}).then(function (data) {
$input.data('update_change', false);
@@ -149,6 +149,7 @@ export class ReorderDialog extends Component {
add_qty: product.qty,
no_variant_attribute_values: JSON.stringify(product.no_variant_attribute_values),
product_custom_attribute_values: JSON.stringify(product.product_custom_attribute_values),
display: false,
});
}
}
@@ -28,10 +28,13 @@ export const cartHandlerMixin = {
* @private
*/
async _addToCartInPage(params) {
params.force_create = true;
const data = await this._rpc({
route: "/shop/cart/update_json",
params: params,
params: {
...params,
display: false,
force_create: true,
},
})
sessionStorage.setItem('website_sale_cart_quantity', data.cart_quantity);
if (data.cart_quantity && (data.cart_quantity !== parseInt($(".my_cart_quantity").text()))) {
@@ -136,7 +136,8 @@ const DynamicSnippetProductsCard = publicWidget.Widget.extend({
route: "/shop/cart/update_json",
params: {
product_id: $card.find('input[data-product-id]').data('product-id'),
add_qty: 1
add_qty: 1,
display: false,
},
});
const $navButton = $('header .o_wsale_my_cart').first();
@@ -192,7 +192,10 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin,
}
return this._rpc({
route: "/shop/cart/update_json",
params: this._getCartUpdateJsonParams(productID, qty),
params: {
...this._getCartUpdateJsonParams(productID, qty),
display: false,
},
}).then(function (data) {
sessionStorage.setItem('website_sale_cart_quantity', data.cart_quantity);
wSaleUtils.updateCartNavBar(data);