【问题标题】:Magento2 restore quote when click on browser back button from payment page从付款页面单击浏览器后退按钮时,Magento2 恢复报价
【发布时间】:2020-05-23 10:15:37
【问题描述】:

当我从 magento2 网站下订单并进入支付页面时,当我从支付页面点击浏览器的后退按钮并重定向到 magento2 webiste 购物车变空时,我需要恢复购物车中的商品,以便当我点击后退按钮时支付页面的浏览器

【问题讨论】:

  • 有什么想法......?

标签: button back


【解决方案1】:

当您单击下订单按钮时​​,该订单已下达,报价已被删除。

这是解决方案。在结帐页面上为事件 controller_action_predispatch_checkout_index_index 创建一个观察者

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_checkout_index_index">
        <observer name="initiate_checkout_onepage" instance="YourObserverClass" />
    </event>
</config>

然后,在 YourObserverClass 上,根据结帐会话获取最后一个订单并恢复最后一个报价,如下所示:

    private $checkoutSession;

    public function __construct(
        \Magento\Checkout\Model\Session\Proxy $checkoutSession
    ) {
        $this->checkoutSession = $checkoutSession;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $lastRealOrder = $this->checkoutSession->getLastRealOrder();
        if ($lastRealOrder->getPayment()) {

            if ($lastRealOrder->getData('state') === 'new' && $lastRealOrder->getData('status') === 'pending') {
                $this->checkoutSession->restoreQuote();
            }
        }
        return true;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    相关资源
    最近更新 更多