Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Dynamically update cart icon after adding products from a reorder popup in Custom Odoo portal

Odoberať

Get notified when there's activity on this post

This question has been flagged
portal
1 Odpoveď
310 Zobrazenia
Avatar
Saksham Khanal

I’ve built a custom portal dashboard in Odoo with a “reorder” feature. When a user clicks reorder, a popup appears showing products from a previous order, and the user can add them back to the cart.

The problem: after adding products via the popup, the cart icon in the navigation bar does not update automatically. By default, Odoo’s “Order Again” redirects users to the shop/cart page, which updates the cart icon, but I don’t want to redirect—the popup closes instead.

I want a clean way to update or rerender the cart icon dynamically after adding products from the popup, ideally using Odoo’s framework (RPC calls, JS widgets, or events) rather than direct DOM hacks.


website_sale_reorder.js

export class ReorderConfirmationDialog extends ConfirmationDialog {

static template = "website_sale.ReorderConfirmationDialog";

}

export class ReorderDialog extends Component {

static template = "website_sale.ReorderModal";

static props = {

close: Function,

orderId: Number,

accessToken: String,

};

static components = {

Dialog,

};

setup() {

this.orm = useService("orm");

this.dialogService = useService("dialog");

this.formatCurrency = formatCurrency;

onWillStart(this.onWillStartHandler.bind(this));

}

async onWillStartHandler() {

// Cart Qty should not change while the dialog is opened.

this.cartQty = parseInt(sessionStorage.getItem("website_sale_cart_quantity"));

if (!this.cartQty) {

this.cartQty = await rpc("/shop/cart/quantity");

}

// Get required information about the order

this.content = await rpc("/my/orders/reorder_modal_content", {

order_id: this.props.orderId,

access_token: this.props.accessToken,

});

// Get required information about each products

for (const product of this.content.products) {

product.debouncedLoadProductCombinationInfo = debounceFn(() => {

this.loadProductCombinationInfo(product).then(this.render.bind(this));

}, 200);

}

}

get total() {

return this.content.products.reduce((total, product) => {

if (product.add_to_cart_allowed) {

total += product.combinationInfo.price * product.qty;

}

return total;

}, 0);

}

get hasBuyableProducts() {

return this.content.products.some((product) => product.add_to_cart_allowed);

}

async loadProductCombinationInfo(product) {

for (const comboItem of product.selected_combo_items) {

comboItem.combinationInfo = await rpc("/website_sale/get_combination_info", {

product_template_id: cReorderDialogomboItem.product_template_id,

product_id: comboItem.product_id,

combination: comboItem.combination,

add_qty: comboItem.qty,

context: {

website_sale_no_images: true,

},

});

}

product.combinationInfo = await rpc("/website_sale/get_combination_info", {

product_template_id: product.product_template_id,

product_id: product.product_id,

combination: product.combination,

add_qty: product.qty,

context: {

website_sale_no_images: true,

},

});

}

getWarningForProduct(product) {

if (!product.add_to_cart_allowed) {

return _t("This product is not available for purchase.");

}

return false;

}

changeProductQty(product, newQty) {

const productNewQty = Math.max(0, newQty);

const qtyChanged = productNewQty !== product.qty;

product.qty = productNewQty;

this.render(true);

if (!qtyChanged) {

return;

}

product.debouncedLoadProductCombinationInfo();

}

onChangeProductQtyInput(ev, product) {

const newQty = parseFloat(ev.target.value) || product.qty;

this.changeProductQty(product, newQty);

}

async confirmReorder(ev) {

if (this.confirmed) {

return;

}

this.confirmed = true;

const onConfirm = async () => {

await this.addProductsToCart();

window.location = "/shop/cart";

};

if (this.cartQty) {

// Open confirmation modal

this.dialogService.add(ReorderConfirmationDialog, {

body: _t("Do you wish to clear your cart before adding products to it?"),

confirm: async () => {

await rpc("/shop/cart/clear");

await onConfirm();

},

cancel: onConfirm,

dismiss: () => {}, // Prevents fallback of 'cancel' from Confirmation Dialog

});

} else {

await onConfirm();

}

}

async addProductsToCart() {

for (const product of this.content.products) {

if (!product.add_to_cart_allowed) {

continue;

}

if (product.selected_combo_items.length) {

await rpc("/website_sale/combo_configurator/update_cart", {

combo_product_id: product.product_id,

quantity: product.qty,

selected_combo_items: product.selected_combo_items,

});

} else {

await rpc("/shop/cart/update_json", {

product_id: product.product_id,

add_qty: product.qty,

no_variant_attribute_value_ids: product.no_variant_attribute_value_ids,

product_custom_attribute_values: JSON.stringify(product.product_custom_attribute_values),

display: false,

});

}

}

}

}

This is the dialog that I have inherited and made changes to 


website_sale>templates.xml

<template id="header_cart_link" name="Header Cart Link">

<t t-nocache="The number of products is dynamic, this rendering cannot be cached."

t-nocache-_icon="_icon"

t-nocache-_text="_text"

t-nocache-_badge="_badge"

t-nocache-_badge_class="_badge_class"

t-nocache-_icon_wrap_class="_icon_wrap_class"

t-nocache-_text_class="_text_class"

t-nocache-_item_class="_item_class"

t-nocache-_link_class="_link_class">

<t t-set="website_sale_cart_quantity" t-value="request.session['website_sale_cart_quantity'] if 'website_sale_cart_quantity' in request.session else website.sale_get_order().cart_quantity or 0"/>

<t t-set="show_cart" t-value="website.has_ecommerce_access()"/>

<li t-attf-class="#{_item_class} divider d-none"/> <!-- Make sure the cart and related menus are not folded (see autohideMenu) -->

<li t-attf-class="o_wsale_my_cart #{not show_cart and 'd-none'} #{_item_class}">

<a href="/shop/cart" t-attf-class="#{_link_class}" aria-label="eCommerce cart">

<div t-attf-class="#{_icon_wrap_class}">

<i t-if="_icon" class="fa fa-shopping-cart fa-stack"/>

<sup t-attf-class="my_cart_quantity badge bg-primary #{_badge_class} #{'d-none' if (website_sale_cart_quantity == 0) else ''}" t-esc="website_sale_cart_quantity" t-att-data-order-id="request.session.get('sale_order_id', '')"/>

</div>

<span t-if="_text" t-attf-class="#{_text_class}">My Cart</span>

</a>

</li>

</t>

</template>


This is the template that I want to re-render

0
Avatar
Zrušiť
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


Odoo’s website_sale.cart public widget listens for the updateCart event.

So, after your RPC calls in addProductsToCart(), simply trigger that event using the website’s event bus:


Try the following code.


import { publicWidget } from "@web/legacy/js/public/public_widget";

import { browser } from "@web/core/browser/browser";


async addProductsToCart() {

    for (const product of this.content.products) {

        if (!product.add_to_cart_allowed) continue;


        if (product.selected_combo_items.length) {

            await rpc("/website_sale/combo_configurator/update_cart", {

                combo_product_id: product.product_id,

                quantity: product.qty,

                selected_combo_items: product.selected_combo_items,

            });

        } else {

            await rpc("/shop/cart/update_json", {

                product_id: product.product_id,

                add_qty: product.qty,

                no_variant_attribute_value_ids: product.no_variant_attribute_value_ids,

                product_custom_attribute_values: JSON.stringify(product.product_custom_attribute_values),

                display: false,

            });

        }

    }


    // Trigger cart update after products are added

    browser.trigger("updateCart");

}


Hope it helps

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Trying to replace default “Invoices & Bills” breadcrumb in Odoo portal
portal
Avatar
Avatar
1
nov 25
404
is possible to add 2 filters to the web portal similar to searchbar_filters?
portal
Avatar
Avatar
Avatar
2
júl 25
2260
How can I allow one portal user to see another portal user's information (like Sales Orders, Invoices)? Solved
portal
Avatar
Avatar
1
máj 24
3879
Use worksheets in Odoo Portal
portal
Avatar
Avatar
2
feb 24
3015
Portail Access
portal
Avatar
0
apr 23
2118
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now