Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
portal
1 Reply
341 Views
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
Discard
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Trying to replace default “Invoices & Bills” breadcrumb in Odoo portal
portal
Avatar
Avatar
1
Nov 25
416
is possible to add 2 filters to the web portal similar to searchbar_filters?
portal
Avatar
Avatar
Avatar
2
Jul 25
2276
How can I allow one portal user to see another portal user's information (like Sales Orders, Invoices)? Solved
portal
Avatar
Avatar
1
May 24
3901
Use worksheets in Odoo Portal
portal
Avatar
Avatar
2
Feb 24
3025
Portail Access
portal
Avatar
0
Apr 23
2119
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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