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 11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2011 Adobe
4+ * All Rights Reserved .
55 */
66namespace Magento \Quote \Model ;
77
@@ -1699,23 +1699,12 @@ public function addProduct(
16991699
17001700 $ this ->itemProcessor ->prepare ($ item , $ request , $ candidate );
17011701
1702- // collect errors instead of throwing first one
17031702 if ($ item ->getHasError ()) {
17041703 if (!$ invalidProductAddFlag ) {
17051704 $ this ->deleteItem ($ item );
17061705 }
1707- foreach ($ item ->getMessage (false ) as $ message ) {
1708- if (!in_array ($ message , $ errors )) {
1709- // filter duplicate messages
1710- $ errors [] = $ message ;
1711- }
1712- }
1713- break ;
17141706 }
17151707 }
1716- if (!empty ($ errors )) {
1717- throw new \Magento \Framework \Exception \LocalizedException (__ (implode ("\n" , $ errors )));
1718- }
17191708
17201709 $ this ->_eventManager ->dispatch ('sales_quote_product_add_after ' , ['items ' => $ items ]);
17211710 return $ parentItem ;
Original file line number Diff line number Diff line change 11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2011 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -130,4 +130,28 @@ public function execute()
130130
131131 return $ resultRedirect ;
132132 }
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+ }
133157}
Original file line number Diff line number Diff line change @@ -598,6 +598,11 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
598598 if (is_string ($ item )) {
599599 throw new \Magento \Framework \Exception \LocalizedException (__ ($ item ));
600600 }
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+ }
601606 }
602607 }
603608 }
You can’t perform that action at this time.
0 commit comments