Skip to Content
Menu
This question has been flagged

I moved my header cart snippet (the cart icon?) outside #top_menu and now the pop-up isn't shown when you hover over it.


This makes sense since the selector is 

selector: '#top_menu a[href$="/shop/cart"]',

inside this file (at the very top)

https://github.com/odoo/odoo/blob/4b8eef24d60a8194f0548f71d8a4e5c1902ac65d/addons/website_sale/static/src/js/website_sale.js


How can I override that selector property so it uses another ID instead of #top_menu?


Avatar
Discard
Best Answer

Try this, To override the selector property in the website_sale module, you will need to create a custom module that depends on the website_sale module. In your custom module, you can define a new website_sale JavaScript class that extends the existing website_sale class and overrides the selector property with your desired ID.

Here is an example of how you could do this:

odoo.define('my_custom_module', function (require) {
    "use strict";

    // Require the original website_sale module so we can extend it
    var website_sale = require('website_sale');

    // Define our custom website_sale class that extends the original
    var CustomWebsiteSale = website_sale.include({
        // Override the selector property with our desired ID
        selector: '#my_custom_id a[href$="/shop/cart"]',
    });

    // Return our custom class to be used in the frontend
    return CustomWebsiteSale;
});

You will need to make sure that your custom module depends on the website_sale module, so it is loaded after the website_sale module, and that you add the necessary assets to your custom module so the frontend knows to use your custom class instead of the original website_sale class. You can do this by adding the following lines to your custom module's __manifest__.py file:

'depends': ['website_sale'], 'js': ['static/src/js/website_sale.js'],

Avatar
Discard
Author Best Answer

Thanks, that did the trick :)

Avatar
Discard
Related Posts Replies Views Activity
3
Feb 23
9242
1
Oct 23
2886
1
Aug 23
1961
1
Mar 22
5463
1
Nov 21
2483