getProductSalableQty = Bootstrap::getObjectManager()->get(GetProductSalableQtyInterface::class); $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); $this->stockRepository = Bootstrap::getObjectManager()->get(StockRepositoryInterface::class); $this->websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepositoryInterface::class); $this->reservationBuilder = Bootstrap::getObjectManager()->get(ReservationBuilderInterface::class); $this->appendReservations = Bootstrap::getObjectManager()->get(AppendReservationsInterface::class); $this->cleanupReservations = Bootstrap::getObjectManager()->get(CleanupReservationsInterface::class); $this->stockManagement = Bootstrap::getObjectManager()->get(StockManagement::class); } /** * We broke transaction during indexation so we need to clean db state manually */ protected function tearDown() { $this->cleanupReservations->execute(); } /** * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php * * @magentoDbIsolation disabled */ public function testRevertProductsSale() { self::assertEquals(8.5, $this->getProductSalableQty->execute('SKU-1', 10)); $product = $this->productRepository->get('SKU-1'); $website = $this->websiteRepository->get('eu_website'); $this->stockManagement->backItemQty($product->getId(), 3.5, $website->getId()); self::assertEquals(12, $this->getProductSalableQty->execute('SKU-1', 10)); $this->appendReservations->execute([ // reserved 3.5 units for cleanup $this->reservationBuilder->setStockId(10)->setSku('SKU-1')->setQuantity(-3.5)->build(), ]); } }