[FIX] website_sale: check selector before use it

Steps to reproduce:
- install website_sale;
- with web editor add a language selector to the top bar menu;
- go to the page '/shop/cart';
- click on the cart.

Issue:
A traceback appears.

Cause:
We use the property of a HTML element without checking its presence.

opw-3246545

closes odoo/odoo#117966

X-original-commit: e6829c38ff3fc0139583be94bf6f86c9acaab8fa
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-04-07 09:29:57 +02:00
parent 8d48cb971a
commit 421ebc45f1
@@ -139,7 +139,7 @@ publicWidget.registry.websiteSaleCartLink = publicWidget.Widget.extend({
if ('website_sale_cart_quantity' in sessionStorage) {
this.cartQty = sessionStorage.getItem('website_sale_cart_quantity');
}
if (this.el.querySelector('.my_cart_quantity').innerText != this.cartQty) {
if (this.el.querySelector('.my_cart_quantity')?.innerText != this.cartQty) {
return this._rpc({route: "/shop/cart/quantity"}).then((cartQty) => {
this.cartQty = cartQty;
sessionStorage.setItem('website_sale_cart_quantity', this.cartQty);
@@ -150,7 +150,7 @@ publicWidget.registry.websiteSaleCartLink = publicWidget.Widget.extend({
* @private
*/
_updateCartQuantityText() {
if (this.cartQty !== undefined) {
if (this.cartQty !== undefined && this.el.querySelector('.my_cart_quantity')) {
this.el.querySelector('.my_cart_quantity').innerText = this.cartQty;
}
}