44
55use Magento \Framework \Event \Observer as EventObserver ;
66use Magento \Framework \Event \ObserverInterface ;
7- use Magento \CatalogInventory \Api \StockRegistryInterface ;
87use Magento \Store \Api \StoreRepositoryInterface ;
98use Magento \InventorySales \Model \ResourceModel \GetAssignedStockIdForWebsite \Proxy as GetAssignedStockIdForWebsiteProxy ;
109use Magento \InventoryReservationsApi \Model \ReservationBuilderInterface \Proxy as ReservationBuilderInterfaceProxy ;
@@ -32,31 +31,23 @@ class SubtractInventoryObserver implements ObserverInterface
3231 */
3332 private $ appendReservations ;
3433
35- /**
36- * @var StockRegistryInterface
37- */
38- private $ stockRegistry ;
39-
4034 /**
4135 * SubtractInventoryObserver constructor.
4236 * @param StoreRepositoryInterface $storeRepository
4337 * @param GetAssignedStockIdForWebsiteProxy $getAssignedStockIdForWebsite
4438 * @param ReservationBuilderInterfaceProxy $reservationBuilder
4539 * @param AppendReservationsInterfaceProxy $appendReservations
46- * @param StockRegistryInterface $stockRegistry
4740 */
4841 public function __construct (
4942 StoreRepositoryInterface $ storeRepository ,
5043 GetAssignedStockIdForWebsiteProxy $ getAssignedStockIdForWebsite ,
5144 ReservationBuilderInterfaceProxy $ reservationBuilder ,
52- AppendReservationsInterfaceProxy $ appendReservations ,
53- StockRegistryInterface $ stockRegistry
45+ AppendReservationsInterfaceProxy $ appendReservations
5446 ) {
5547 $ this ->storeRepository = $ storeRepository ;
5648 $ this ->getAssignedStockIdForWebsite = $ getAssignedStockIdForWebsite ;
5749 $ this ->reservationBuilder = $ reservationBuilder ;
5850 $ this ->appendReservations = $ appendReservations ;
59- $ this ->stockRegistry = $ stockRegistry ;
6051 }
6152
6253 /**
@@ -80,7 +71,6 @@ public function execute(EventObserver $observer)
8071 $ storeId = $ order ->getStoreId ();
8172 $ website = $ this ->storeRepository ->getById ($ storeId )->getWebsite ();
8273 $ websiteCode = $ website ->getCode ();
83- $ websiteId = $ website ->getId ();
8474
8575 if (
8676 interface_exists (\Magento \InventoryReservationsApi \Model \ReservationBuilderInterface::class)
@@ -105,21 +95,7 @@ interface_exists(\Magento\InventoryReservationsApi\Model\ReservationBuilderInter
10595 }
10696
10797 $ this ->appendReservations ->execute ($ reservations );
108- } else {
109- foreach ($ order ->getAllItems () as $ item ) {
110- $ itemData = $ item ->getData ();
111-
112- $ itemQty = $ itemData ['qty_ordered ' ] ?? null ;
113- $ itemSku = $ itemData ['sku ' ] ?? null ;
114-
115- $ stockItem = $ this ->stockRegistry ->getStockItemBySku ($ itemSku , $ websiteId );
116- $ currentQty = (float ) $ stockItem ->getQty ();
117- $ stockItem ->setQty ($ currentQty - $ itemQty );
118- $ stockItem ->setIsInStock ((($ currentQty - $ itemQty ) > 0 ) ? 1 : 0 );
119- $ this ->stockRegistry ->updateStockItemBySku ($ itemSku , $ stockItem );
120- }
12198 }
122-
12399 $ order ->setInventoryProcessed (true )->save ();
124100 return $ this ;
125101 }
0 commit comments