【发布时间】:2018-08-08 13:33:32
【问题描述】:
我想将用户重定向到将产品添加到购物车的结帐页面,请帮助。
【问题讨论】:
-
@shinoy shaji 请再次阅读我的问题,我说的是 Magento 2。感谢您的宝贵时间
-
感谢大家的回答。我自己解决了。
-
你是怎么做到的??
标签: magento2.2
我想将用户重定向到将产品添加到购物车的结帐页面,请帮助。
【问题讨论】:
标签: magento2.2
@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]);
}
将产品添加到购物车后,这会将用户重定向到结帐页面。并删除了成功添加到购物车的消息。
注意:请创建您自己的自定义模块,以免覆盖核心文件。希望您知道如何创建自己的模块。
【讨论】: