66 */
77namespace 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+ */
916class 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