stockIndexer = $objectManager->get(StockIndexer::class); $this->getStockItemData = $objectManager->get(GetStockItemData::class); $this->groupedProducts = $objectManager->get(Grouped::class); $this->getSourceItemsBySku = $objectManager->get(GetSourceItemsBySkuInterface::class); $this->sourceItemSave = $objectManager->get(SourceItemsSaveInterface::class); $this->sourceItemRepository = $objectManager->get(SourceItemRepositoryInterface::class); $this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); $this->productRepository = $objectManager->get(ProductRepositoryInterface::class); $this->storeManager = $objectManager->get(StoreManagerInterface::class); $this->storeRepository = $objectManager->get(StoreRepository::class); $this->removeIndexData = $objectManager->get(RemoveIndexData::class); $this->removeIndexData->execute([10, 20, 30]); } /** * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php * @magentoDataFixture ../../../../app/code/Magento/InventoryGroupedProduct/Test/_files/default_stock_grouped_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/InventorySalesApi/Test/_files/stock_website_sales_channels.php * @magentoDataFixture ../../../../app/code/Magento/InventoryGroupedProductIndexer/Test/_files/source_items_grouped_multiple.php * * @magentoDbIsolation disabled */ public function testReindexList() { $groupedSku = 'grouped_in_stock'; $this->stockIndexer->executeList([10, 20, 30]); $stockItemData = $this->getStockItemData->execute($groupedSku, 10); self::assertEquals(1, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); $stockItemData = $this->getStockItemData->execute($groupedSku, 20); self::assertEquals(1, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); $stockItemData = $this->getStockItemData->execute($groupedSku, 30); self::assertEquals(1, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); } /** * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php * @magentoDataFixture ../../../../app/code/Magento/InventoryGroupedProductIndexer/Test/_files/custom_stock_with_eu_website_grouped_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/InventoryGroupedProductIndexer/Test/_files/source_items_grouped_multiple.php * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php * * @magentoDbIsolation disabled */ public function testReindexListSetAllSimplesOutOfStock() { $groupedSku = 'grouped_in_stock'; $store = $this->storeRepository->get('store_for_us_website'); $this->storeManager->setCurrentStore($store->getId()); $groupedProduct = $this->productRepository->get($groupedSku); $children = $this->groupedProducts->getLinkedProducts($groupedProduct); /** @var Product $child */ foreach ($children as $child) { $sku = $child->getSku(); $sourceItems = $this->getSourceItemsBySku->execute($sku); $changesSourceItems = []; foreach ($sourceItems as $sourceItem) { $sourceItem->setStatus(SourceItemInterface::STATUS_OUT_OF_STOCK); $changesSourceItems[] = $sourceItem; } $this->sourceItemSave->execute($changesSourceItems); } $this->removeIndexData->execute([10, 20, 30]); $this->stockIndexer->executeList([10, 20, 30]); $stockItemData = $this->getStockItemData->execute($groupedSku, 10); self::assertEquals(0, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); $stockItemData = $this->getStockItemData->execute($groupedSku, 20); self::assertEquals(0, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); $stockItemData = $this->getStockItemData->execute($groupedSku, 30); self::assertEquals(0, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); } /** * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php * @magentoDataFixture ../../../../app/code/Magento/InventoryGroupedProductIndexer/Test/_files/custom_stock_with_eu_website_grouped_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/InventoryGroupedProductIndexer/Test/_files/source_items_grouped_multiple.php * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php * * @magentoDbIsolation disabled */ public function testReindexListSetAllEuSimplesOutOfStock() { $groupedSku = 'grouped_in_stock'; $sourceCodes = ['eu-1', 'eu-2', 'eu-3']; $store = $this->storeRepository->get('store_for_us_website'); $this->storeManager->setCurrentStore($store->getId()); $groupedProduct = $this->productRepository->get($groupedSku); $children = $this->groupedProducts->getLinkedProducts($groupedProduct); foreach ($children as $child) { $sku = $child->getSku(); $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, $sku) ->addFilter(SourceItemInterface::SOURCE_CODE, $sourceCodes, 'in') ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria); $changesSourceItems = []; foreach ($sourceItems->getItems() as $sourceItem) { $sourceItem->setStatus(SourceItemInterface::STATUS_OUT_OF_STOCK); $changesSourceItems[] = $sourceItem; } $this->sourceItemSave->execute($changesSourceItems); } $this->removeIndexData->execute([10, 20, 30]); $this->stockIndexer->executeList([10, 20, 30]); $stockItemData = $this->getStockItemData->execute($groupedSku, 10); self::assertEquals(0, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); $stockItemData = $this->getStockItemData->execute($groupedSku, 20); self::assertEquals(1, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); $stockItemData = $this->getStockItemData->execute($groupedSku, 30); self::assertEquals(1, $stockItemData[GetStockItemDataInterface::IS_SALABLE]); } }