【问题标题】:How to redirect to checkout page after add to cart on single product page Magento 2?在单个产品页面 Magento 2 上添加到购物车后如何重定向到结帐页面?
【发布时间】:2018-08-08 13:33:32
【问题描述】:

我想将用户重定向到将产品添加到购物车的结帐页面,请帮助。

【问题讨论】:

标签: magento2.2


【解决方案1】:

@alexeyboltynov 首先,您已从 magento 2 管理员启用跳过购物车选项。您可以在主题设置中轻松找到该选项。

而且你必须覆盖核心文件路径: "vendor\magento\module-checkout\Controller\Cart\Add.php"

查找代码:

if (!$this->_checkoutSession->getNoCartRedirect(true)) {
    if (!$this->cart->getQuote()->getHasError()) {
        if ($this->shouldRedirectToCart()) {
            $message = __(
                'You added %1 to your shopping cart.',
                     $product->getName()
                );
                    $this->messageManager->addSuccessMessage($message);
        } else {
                        $this->messageManager->addComplexSuccessMessage(
                            'addCartSuccessMessage',
                            [
                                'product_name' => $product->getName(),
                                'cart_url' => $this->getCartUrl(),
                            ]
                        );
                    }
                }
                return $this->goBack(null, $product);
            }

将其替换为:

if (!$this->_checkoutSession->getNoCartRedirect(true)) {
           return $this->resultRedirectFactory->create()->setPath('checkout', ['_current' => true]);
            }

将产品添加到购物车后,这会将用户重定向到结帐页面。并删除了成功添加到购物车的消息。

注意:请创建您自己的自定义模块,以免覆盖核心文件。希望您知道如何创建自己的模块。

【讨论】:

    猜你喜欢
    • 2014-08-30
    • 2016-09-29
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 2021-12-26
    相关资源
    最近更新 更多