Skip to content

Commit 49bee81

Browse files
committed
Don't add a link to the cart if customer is redirected to cart already after adding a product
1 parent f5f40fa commit 49bee81

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

app/code/Magento/Checkout/Controller/Cart.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ protected function getBackUrl($defaultUrl = null)
118118
return $returnUrl;
119119
}
120120

121-
$shouldRedirectToCart = $this->_scopeConfig->getValue(
122-
'checkout/cart/redirect_to_cart',
123-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
124-
);
125-
126-
if ($shouldRedirectToCart || $this->getRequest()->getParam('in_cart')) {
121+
if ($this->shouldRedirectToCart() || $this->getRequest()->getParam('in_cart')) {
127122
if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) {
128123
$this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl());
129124
}
@@ -132,4 +127,15 @@ protected function getBackUrl($defaultUrl = null)
132127

133128
return $defaultUrl;
134129
}
130+
131+
/**
132+
* @return bool
133+
*/
134+
protected function shouldRedirectToCart()
135+
{
136+
return $this->_scopeConfig->isSetFlag(
137+
'checkout/cart/redirect_to_cart',
138+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
139+
);
140+
}
135141
}

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,21 @@ public function execute()
122122

123123
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
124124
if (!$this->cart->getQuote()->getHasError()) {
125-
$this->messageManager->addComplexSuccessMessage(
126-
'addCartSuccessMessage',
127-
[
128-
'product_name' => $product->getName(),
129-
'cart_url' => $this->getCartUrl(),
130-
]
131-
);
125+
if ($this->shouldRedirectToCart()) {
126+
$message = __(
127+
'You added %1 to your shopping cart.',
128+
$product->getName()
129+
);
130+
$this->messageManager->addSuccessMessage($message);
131+
} else {
132+
$this->messageManager->addComplexSuccessMessage(
133+
'addCartSuccessMessage',
134+
[
135+
'product_name' => $product->getName(),
136+
'cart_url' => $this->getCartUrl(),
137+
]
138+
);
139+
}
132140
}
133141
return $this->goBack(null, $product);
134142
}

0 commit comments

Comments
 (0)