Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix > Adding Success Message > Recent Ordered #9852

Merged
merged 5 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/code/Magento/Checkout/Controller/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ abstract class Cart extends \Magento\Framework\App\Action\Action implements View
*/
protected $cart;

/**
* @var \Magento\Framework\Escaper
*/
protected $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 \Magento\Framework\Escaper $escaper
* @codeCoverageIgnore
*/
public function __construct(
Expand All @@ -53,13 +59,15 @@ public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
CustomerCart $cart
CustomerCart $cart,
\Magento\Framework\Escaper $escaper = null
) {
$this->_formKeyValidator = $formKeyValidator;
$this->_scopeConfig = $scopeConfig;
$this->_checkoutSession = $checkoutSession;
$this->_storeManager = $storeManager;
$this->cart = $cart;
$this->cart = $cart;
$this->escaper = $escaper ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

parent::__construct($context);
}

Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Checkout/Controller/Cart/Addgroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
5 changes: 4 additions & 1 deletion app/code/Magento/Checkout/Controller/Cart/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Index extends \Magento\Checkout\Controller\Cart
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
* @param \Magento\Checkout\Model\Cart $cart
* @param \Magento\Framework\Escaper $escaper
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @codeCoverageIgnore
*/
Expand All @@ -31,6 +32,7 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
\Magento\Checkout\Model\Cart $cart,
\Magento\Framework\Escaper $escaper,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this argument must be optional according to parent class.
Please update all other child classes of \Magento\Checkout\Controller\Cart with new optional argument

\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
parent::__construct(
Expand All @@ -39,7 +41,8 @@ public function __construct(
$checkoutSession,
$storeManager,
$formKeyValidator,
$cart
$cart,
$escaper
);
$this->resultPageFactory = $resultPageFactory;
}
Expand Down