File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
app/code/Magento/Checkout/Controller Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -38,13 +38,19 @@ abstract class Cart extends \Magento\Framework\App\Action\Action implements View
38
38
*/
39
39
protected $ cart ;
40
40
41
+ /**
42
+ * @var \Magento\Framework\Escaper
43
+ */
44
+ protected $ escaper ;
45
+
41
46
/**
42
47
* @param \Magento\Framework\App\Action\Context $context
43
48
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
44
49
* @param \Magento\Checkout\Model\Session $checkoutSession
45
50
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
46
51
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
47
52
* @param CustomerCart $cart
53
+ * @param \Magento\Framework\Escaper $escaper
48
54
* @codeCoverageIgnore
49
55
*/
50
56
public function __construct (
@@ -53,13 +59,15 @@ public function __construct(
53
59
\Magento \Checkout \Model \Session $ checkoutSession ,
54
60
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
55
61
\Magento \Framework \Data \Form \FormKey \Validator $ formKeyValidator ,
56
- CustomerCart $ cart
62
+ CustomerCart $ cart ,
63
+ \Magento \Framework \Escaper $ escaper = null
57
64
) {
58
65
$ this ->_formKeyValidator = $ formKeyValidator ;
59
66
$ this ->_scopeConfig = $ scopeConfig ;
60
67
$ this ->_checkoutSession = $ checkoutSession ;
61
68
$ this ->_storeManager = $ storeManager ;
62
- $ this ->cart = $ cart ;
69
+ $ this ->cart = $ cart ;
70
+ $ this ->escaper = $ escaper ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (\Magento \Framework \Escaper::class);
63
71
parent ::__construct ($ context );
64
72
}
65
73
Original file line number Diff line number Diff line change @@ -23,6 +23,13 @@ public function execute()
23
23
foreach ($ itemsCollection as $ item ) {
24
24
try {
25
25
$ this ->cart ->addOrderItem ($ item , 1 );
26
+ if (!$ this ->cart ->getQuote ()->getHasError ()) {
27
+ $ message = __ (
28
+ 'You added %1 to your shopping cart. ' ,
29
+ $ this ->escaper ->escapeHtml ($ item ->getName ())
30
+ );
31
+ $ this ->messageManager ->addSuccessMessage ($ message );
32
+ }
26
33
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
27
34
if ($ this ->_checkoutSession ->getUseNotice (true )) {
28
35
$ this ->messageManager ->addNotice ($ e ->getMessage ());
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Index extends \Magento\Checkout\Controller\Cart
21
21
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
22
22
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
23
23
* @param \Magento\Checkout\Model\Cart $cart
24
+ * @param \Magento\Framework\Escaper $escaper
24
25
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
25
26
* @codeCoverageIgnore
26
27
*/
@@ -31,6 +32,7 @@ public function __construct(
31
32
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
32
33
\Magento \Framework \Data \Form \FormKey \Validator $ formKeyValidator ,
33
34
\Magento \Checkout \Model \Cart $ cart ,
35
+ \Magento \Framework \Escaper $ escaper ,
34
36
\Magento \Framework \View \Result \PageFactory $ resultPageFactory
35
37
) {
36
38
parent ::__construct (
@@ -39,7 +41,8 @@ public function __construct(
39
41
$ checkoutSession ,
40
42
$ storeManager ,
41
43
$ formKeyValidator ,
42
- $ cart
44
+ $ cart ,
45
+ $ escaper
43
46
);
44
47
$ this ->resultPageFactory = $ resultPageFactory ;
45
48
}
You can’t perform that action at this time.
0 commit comments