Magento2 Addtocart 成功消息消失

问题描述 投票:0回答:1

点击添加到购物车按钮成功消息消失,同时详细页面和列表页面。

我对 messages.js 使用了一些代码更改

$.cookieStorage.setConf({path: '/', expires: -1}).set('mage-messages', null);

那也行不通。

任何人给建议 magento2.4 success message flashout immediately.

我希望在添加到购物车后正确加载成功消息。

message magento2.4
1个回答
0
投票

我正在使用 Magento 2.4.5,我在 PDP 和 PLP 上添加到购物车成功消息时遇到问题,成功消息消失得太快了。

我找到了解决方案,可能会帮助同一条船上的人。

请根据您的要求进行修改。

对我来说工作解决方案是

Overwrite Magento_Customer/js/customer-data.js

修改功能

onAjaxComplete

如果部分只有

["messages"] then use settimeout

我将功能替换为

onAjaxComplete: function (jsonResponse, settings) {
            var sections,
                redirects;

            if (settings.type.match(/post|put|delete/i)) {
                sections = sectionConfig.getAffectedSections(settings.url);
                if(JSON.stringify(sections) !=='["messages"]') {
                    if (sections && sections.length) {
                        this.invalidate(sections);
                        redirects = ['redirect', 'backUrl'];
    
                        if (_.isObject(jsonResponse) && !_.isEmpty(_.pick(jsonResponse, redirects))) { //eslint-disable-line
                            return;
                        }
                        this.reload(sections, true);
                    }
                } else {
                    setTimeout(function() { 
                        sections = $.parseJSON('["messages"]');
                        customerData.reload(sections, true);
                    }, 5000);
                }
            }
        },
© www.soinside.com 2019 - 2024. All rights reserved.