Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
2665 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur Beste antwoord

Thanks, that did the trick :)

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
feb. 23
11161
1
okt. 23
3161
1
aug. 23
2830
1
mrt. 22
6567
1
nov. 21
3413