From f6cbd5b90c32255500ccafae8788713e65396fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Mon, 5 Jun 2017 18:58:32 -0300 Subject: [PATCH 1/7] Bugfix > Adding Success Message > Recent Ordered --- app/code/Magento/Checkout/Controller/Cart/Addgroup.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php index 046dd0b8082c1..6c0da47889767 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php +++ b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php @@ -23,6 +23,10 @@ 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.', $item->getName()); + $this->messageManager->addSuccessMessage($message); + } } catch (\Magento\Framework\Exception\LocalizedException $e) { if ($this->_checkoutSession->getUseNotice(true)) { $this->messageManager->addNotice($e->getMessage()); From 4de81a5d788fb986e8742367101b50e42168587c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Thu, 8 Jun 2017 14:33:15 -0300 Subject: [PATCH 2/7] escaping the product name --- app/code/Magento/Checkout/Controller/Cart/Addgroup.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php index 6c0da47889767..8f4b30f81b8c0 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php +++ b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php @@ -24,7 +24,10 @@ public function execute() try { $this->cart->addOrderItem($item, 1); if (!$this->cart->getQuote()->getHasError()) { - $message = __('You added %1 to your shopping cart.', $item->getName()); + $message = __( + 'You added %1 to your shopping cart.', + $this->escaper->escapeHtml($item->getName()) + ); $this->messageManager->addSuccessMessage($message); } } catch (\Magento\Framework\Exception\LocalizedException $e) { From 193f92b5215e05070b132dfbd2e4f1c8057e1e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Thu, 8 Jun 2017 15:50:01 -0300 Subject: [PATCH 3/7] Add the Instance of the Escaper in Cart Controller --- app/code/Magento/Checkout/Controller/Cart.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Controller/Cart.php b/app/code/Magento/Checkout/Controller/Cart.php index f6c59562ee942..0a54004442df0 100644 --- a/app/code/Magento/Checkout/Controller/Cart.php +++ b/app/code/Magento/Checkout/Controller/Cart.php @@ -7,6 +7,7 @@ use Magento\Catalog\Controller\Product\View\ViewInterface; use Magento\Checkout\Model\Cart as CustomerCart; +use Magento\Framework\Escaper; /** * Shopping cart controller @@ -38,6 +39,11 @@ 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 @@ -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, + Escaper $escaper ) { $this->_formKeyValidator = $formKeyValidator; $this->_scopeConfig = $scopeConfig; $this->_checkoutSession = $checkoutSession; $this->_storeManager = $storeManager; - $this->cart = $cart; + $this->cart = $cart; + $this->escaper = $escaper; parent::__construct($context); } From 57c5fedbc1ff1107a8e3094a940139f68419c238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Thu, 8 Jun 2017 15:55:08 -0300 Subject: [PATCH 4/7] Add the Instance of the Escaper in Cart Controller Index --- app/code/Magento/Checkout/Controller/Cart/Index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/Controller/Cart/Index.php b/app/code/Magento/Checkout/Controller/Cart/Index.php index 3fb582d35e28a..438fa2b634c0a 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Index.php +++ b/app/code/Magento/Checkout/Controller/Cart/Index.php @@ -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 */ @@ -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, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct( @@ -39,7 +41,8 @@ public function __construct( $checkoutSession, $storeManager, $formKeyValidator, - $cart + $cart, + $escaper ); $this->resultPageFactory = $resultPageFactory; } From 58ee67ddde379f7616e8c0d9a0d23ac2fc74da4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Wed, 28 Jun 2017 01:44:53 -0300 Subject: [PATCH 5/7] Checkout Controller Cart > Backward compatible --- app/code/Magento/Checkout/Controller/Cart.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Checkout/Controller/Cart.php b/app/code/Magento/Checkout/Controller/Cart.php index 0a54004442df0..48b85413ef143 100644 --- a/app/code/Magento/Checkout/Controller/Cart.php +++ b/app/code/Magento/Checkout/Controller/Cart.php @@ -7,7 +7,6 @@ use Magento\Catalog\Controller\Product\View\ViewInterface; use Magento\Checkout\Model\Cart as CustomerCart; -use Magento\Framework\Escaper; /** * Shopping cart controller @@ -43,7 +42,7 @@ abstract class Cart extends \Magento\Framework\App\Action\Action implements View * @var \Magento\Framework\Escaper */ protected $escaper; - + /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig @@ -51,6 +50,7 @@ abstract class Cart extends \Magento\Framework\App\Action\Action implements View * @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( @@ -60,14 +60,14 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, CustomerCart $cart, - Escaper $escaper + \Magento\Framework\Escaper $escaper = null ) { $this->_formKeyValidator = $formKeyValidator; $this->_scopeConfig = $scopeConfig; $this->_checkoutSession = $checkoutSession; $this->_storeManager = $storeManager; $this->cart = $cart; - $this->escaper = $escaper; + $this->escaper = $escaper ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class); parent::__construct($context); } From 98478af1829f500c07b32122ba2f36c341fdfe06 Mon Sep 17 00:00:00 2001 From: Oleksii Korshenko Date: Fri, 7 Jul 2017 13:13:38 -0500 Subject: [PATCH 6/7] MAGETWO-69683: Bugfix > Adding Success Message > Recent Ordered #9852 - fixed backward compatibility issue --- app/code/Magento/Checkout/Controller/Cart.php | 14 ++------ .../Checkout/Controller/Cart/Addgroup.php | 33 ++++++++++++++++++- .../Checkout/Controller/Cart/Index.php | 5 +-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Checkout/Controller/Cart.php b/app/code/Magento/Checkout/Controller/Cart.php index 48b85413ef143..f244fe310af27 100644 --- a/app/code/Magento/Checkout/Controller/Cart.php +++ b/app/code/Magento/Checkout/Controller/Cart.php @@ -38,11 +38,6 @@ 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 @@ -50,7 +45,6 @@ abstract class Cart extends \Magento\Framework\App\Action\Action implements View * @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( @@ -59,15 +53,13 @@ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, - CustomerCart $cart, - \Magento\Framework\Escaper $escaper = null + CustomerCart $cart ) { $this->_formKeyValidator = $formKeyValidator; $this->_scopeConfig = $scopeConfig; $this->_checkoutSession = $checkoutSession; $this->_storeManager = $storeManager; - $this->cart = $cart; - $this->escaper = $escaper ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class); + $this->cart = $cart; parent::__construct($context); } @@ -85,7 +77,7 @@ protected function _goBack($backUrl = null) if ($backUrl || $backUrl = $this->getBackUrl($this->_redirect->getRefererUrl())) { $resultRedirect->setUrl($backUrl); } - + return $resultRedirect; } diff --git a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php index 8f4b30f81b8c0..f4a46978a3625 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php +++ b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php @@ -6,8 +6,39 @@ */ namespace Magento\Checkout\Controller\Cart; +use Magento\Checkout\Model\Cart as CustomerCart; +use Magento\Framework\Escaper; +use Magento\Framework\App\ObjectManager; + 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 */ @@ -25,7 +56,7 @@ public function execute() $this->cart->addOrderItem($item, 1); if (!$this->cart->getQuote()->getHasError()) { $message = __( - 'You added %1 to your shopping cart.', + 'You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getName()) ); $this->messageManager->addSuccessMessage($message); diff --git a/app/code/Magento/Checkout/Controller/Cart/Index.php b/app/code/Magento/Checkout/Controller/Cart/Index.php index 438fa2b634c0a..3fb582d35e28a 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Index.php +++ b/app/code/Magento/Checkout/Controller/Cart/Index.php @@ -21,7 +21,6 @@ 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 */ @@ -32,7 +31,6 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Checkout\Model\Cart $cart, - \Magento\Framework\Escaper $escaper, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct( @@ -41,8 +39,7 @@ public function __construct( $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $escaper + $cart ); $this->resultPageFactory = $resultPageFactory; } From aa887ffe147817a4277cec1a5f4bf8912b2e4838 Mon Sep 17 00:00:00 2001 From: Oleksii Korshenko Date: Fri, 7 Jul 2017 13:25:35 -0500 Subject: [PATCH 7/7] MAGETWO-69683: Bugfix > Adding Success Message > Recent Ordered #9852 - fixed static tests --- app/code/Magento/Checkout/Controller/Cart/Addgroup.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php index f4a46978a3625..0fc83536cc3f2 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Addgroup.php +++ b/app/code/Magento/Checkout/Controller/Cart/Addgroup.php @@ -10,6 +10,9 @@ use Magento\Framework\Escaper; use Magento\Framework\App\ObjectManager; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Addgroup extends \Magento\Checkout\Controller\Cart { /** @@ -56,8 +59,8 @@ public function execute() $this->cart->addOrderItem($item, 1); if (!$this->cart->getQuote()->getHasError()) { $message = __( - 'You added %1 to your shopping cart.', - $this->escaper->escapeHtml($item->getName()) + 'You added %1 to your shopping cart.', + $this->escaper->escapeHtml($item->getName()) ); $this->messageManager->addSuccessMessage($message); }