6
6
*/
7
7
namespace Magento \Checkout \Controller \Cart ;
8
8
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
+ */
9
16
class Addgroup extends \Magento \Checkout \Controller \Cart
10
17
{
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
+
11
45
/**
12
46
* @return \Magento\Framework\Controller\Result\Redirect
13
47
*/
@@ -23,6 +57,13 @@ public function execute()
23
57
foreach ($ itemsCollection as $ item ) {
24
58
try {
25
59
$ 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
+ }
26
67
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
27
68
if ($ this ->_checkoutSession ->getUseNotice (true )) {
28
69
$ this ->messageManager ->addNotice ($ e ->getMessage ());
0 commit comments