Skip to content

Commit

Permalink
MAGETWO-69683: Bugfix > Adding Success Message > Recent Ordered #9852
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko authored Jul 10, 2017
2 parents 8ca2748 + aa887ff commit 2c106fd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/Controller/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function _goBack($backUrl = null)
if ($backUrl || $backUrl = $this->getBackUrl($this->_redirect->getRefererUrl())) {
$resultRedirect->setUrl($backUrl);
}

return $resultRedirect;
}

Expand Down
41 changes: 41 additions & 0 deletions app/code/Magento/Checkout/Controller/Cart/Addgroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,42 @@
*/
namespace Magento\Checkout\Controller\Cart;

use Magento\Checkout\Model\Cart as CustomerCart;
use Magento\Framework\Escaper;
use Magento\Framework\App\ObjectManager;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Addgroup extends \Magento\Checkout\Controller\Cart
{
/**
* @var Escaper
*/
private $escaper;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
* @param CustomerCart $cart
* @param Escaper|null $escaper
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
CustomerCart $cart,
Escaper $escaper = null
) {
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
parent::__construct($context, $scopeConfig, $checkoutSession, $storeManager, $formKeyValidator, $cart);
}

/**
* @return \Magento\Framework\Controller\Result\Redirect
*/
Expand All @@ -23,6 +57,13 @@ public function execute()
foreach ($itemsCollection as $item) {
try {
$this->cart->addOrderItem($item, 1);
if (!$this->cart->getQuote()->getHasError()) {
$message = __(
'You added %1 to your shopping cart.',
$this->escaper->escapeHtml($item->getName())
);
$this->messageManager->addSuccessMessage($message);
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
if ($this->_checkoutSession->getUseNotice(true)) {
$this->messageManager->addNotice($e->getMessage());
Expand Down

0 comments on commit 2c106fd

Please sign in to comment.