File tree Expand file tree Collapse file tree 3 files changed +33
-15
lines changed
Controller/Adminhtml/Order/Create Expand file tree Collapse file tree 3 files changed +33
-15
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
namespace Magento \Quote \Model ;
7
7
@@ -1699,23 +1699,12 @@ public function addProduct(
1699
1699
1700
1700
$ this ->itemProcessor ->prepare ($ item , $ request , $ candidate );
1701
1701
1702
- // collect errors instead of throwing first one
1703
1702
if ($ item ->getHasError ()) {
1704
1703
if (!$ invalidProductAddFlag ) {
1705
1704
$ this ->deleteItem ($ item );
1706
1705
}
1707
- foreach ($ item ->getMessage (false ) as $ message ) {
1708
- if (!in_array ($ message , $ errors )) {
1709
- // filter duplicate messages
1710
- $ errors [] = $ message ;
1711
- }
1712
- }
1713
- break ;
1714
1706
}
1715
1707
}
1716
- if (!empty ($ errors )) {
1717
- throw new \Magento \Framework \Exception \LocalizedException (__ (implode ("\n" , $ errors )));
1718
- }
1719
1708
1720
1709
$ this ->_eventManager ->dispatch ('sales_quote_product_add_after ' , ['items ' => $ items ]);
1721
1710
return $ parentItem ;
Original file line number Diff line number Diff line change 1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -130,4 +130,28 @@ public function execute()
130
130
131
131
return $ resultRedirect ;
132
132
}
133
+
134
+ /**
135
+ * Collect all item errors
136
+ *
137
+ * @param $order
138
+ * @return array
139
+ */
140
+ private function getItemErrors ($ order ): array
141
+ {
142
+ $ errors = [];
143
+ $ items = $ order ->getAllItems ();
144
+ foreach ($ items as $ item ) {
145
+ if (!$ item ->getMessage (false )) {
146
+ continue ;
147
+ }
148
+ foreach ($ item ->getMessage (false ) as $ message ) {
149
+ if (!in_array ($ message , $ errors )) {
150
+ $ errors [] = $ message ;
151
+ }
152
+ }
153
+ }
154
+
155
+ return $ errors ;
156
+ }
133
157
}
Original file line number Diff line number Diff line change @@ -598,6 +598,11 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
598
598
if (is_string ($ item )) {
599
599
throw new \Magento \Framework \Exception \LocalizedException (__ ($ item ));
600
600
}
601
+ if ($ item ->getStockStateResult () && $ item ->getStockStateResult ()->getHasError ()) {
602
+ $ this ->messageManager ->addErrorMessage (
603
+ __ ('The product with SKU %sku is out of stock. ' , ['sku ' => $ item ->getSku ()])
604
+ );
605
+ }
601
606
}
602
607
}
603
608
}
You can’t perform that action at this time.
0 commit comments