Skip to content

Commit 2c106fd

Browse files
author
Oleksii Korshenko
authored
MAGETWO-69683: Bugfix > Adding Success Message > Recent Ordered #9852
2 parents 8ca2748 + aa887ff commit 2c106fd

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function _goBack($backUrl = null)
7777
if ($backUrl || $backUrl = $this->getBackUrl($this->_redirect->getRefererUrl())) {
7878
$resultRedirect->setUrl($backUrl);
7979
}
80-
80+
8181
return $resultRedirect;
8282
}
8383

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,42 @@
66
*/
77
namespace Magento\Checkout\Controller\Cart;
88

9+
use Magento\Checkout\Model\Cart as CustomerCart;
10+
use Magento\Framework\Escaper;
11+
use Magento\Framework\App\ObjectManager;
12+
13+
/**
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
916
class Addgroup extends \Magento\Checkout\Controller\Cart
1017
{
18+
/**
19+
* @var Escaper
20+
*/
21+
private $escaper;
22+
23+
/**
24+
* @param \Magento\Framework\App\Action\Context $context
25+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
26+
* @param \Magento\Checkout\Model\Session $checkoutSession
27+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
28+
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
29+
* @param CustomerCart $cart
30+
* @param Escaper|null $escaper
31+
*/
32+
public function __construct(
33+
\Magento\Framework\App\Action\Context $context,
34+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
35+
\Magento\Checkout\Model\Session $checkoutSession,
36+
\Magento\Store\Model\StoreManagerInterface $storeManager,
37+
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
38+
CustomerCart $cart,
39+
Escaper $escaper = null
40+
) {
41+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
42+
parent::__construct($context, $scopeConfig, $checkoutSession, $storeManager, $formKeyValidator, $cart);
43+
}
44+
1145
/**
1246
* @return \Magento\Framework\Controller\Result\Redirect
1347
*/
@@ -23,6 +57,13 @@ public function execute()
2357
foreach ($itemsCollection as $item) {
2458
try {
2559
$this->cart->addOrderItem($item, 1);
60+
if (!$this->cart->getQuote()->getHasError()) {
61+
$message = __(
62+
'You added %1 to your shopping cart.',
63+
$this->escaper->escapeHtml($item->getName())
64+
);
65+
$this->messageManager->addSuccessMessage($message);
66+
}
2667
} catch (\Magento\Framework\Exception\LocalizedException $e) {
2768
if ($this->_checkoutSession->getUseNotice(true)) {
2869
$this->messageManager->addNotice($e->getMessage());

0 commit comments

Comments
 (0)