From bb96e48ffcc2baae3eda414170c2f6e3d9d686e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szyma=C5=84ski?= Date: Thu, 5 Oct 2017 08:25:30 +0200 Subject: [PATCH] Add linkage between Default Source and Stock --- .../InventoryCatalog/Setup/InstallData.php | 20 +++++++++ .../Api/GetDefaultStockToSourceLinkTest.php | 42 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php diff --git a/app/code/Magento/InventoryCatalog/Setup/InstallData.php b/app/code/Magento/InventoryCatalog/Setup/InstallData.php index 6862da766f40..2613297f0ff4 100644 --- a/app/code/Magento/InventoryCatalog/Setup/InstallData.php +++ b/app/code/Magento/InventoryCatalog/Setup/InstallData.php @@ -15,6 +15,7 @@ use Magento\InventoryApi\Api\Data\StockInterfaceFactory; use Magento\InventoryApi\Api\Data\StockInterface; use Magento\InventoryApi\Api\StockRepositoryInterface; +use Magento\InventoryApi\Api\AssignSourcesToStockInterface; use Magento\Framework\Api\DataObjectHelper; /** @@ -47,11 +48,17 @@ class InstallData implements InstallDataInterface */ private $dataObjectHelper; + /** + * @var AssignSourcesToStockInterface + */ + private $assignSourcesToStock; + /** * @param SourceRepositoryInterface $sourceRepository * @param SourceInterfaceFactory $sourceFactory * @param StockRepositoryInterface $stockRepository * @param StockInterfaceFactory $stockFactory + * @param AssignSourcesToStockInterface $assignSourcesToStock * @param DataObjectHelper $dataObjectHelper */ public function __construct( @@ -59,12 +66,14 @@ public function __construct( SourceInterfaceFactory $sourceFactory, StockRepositoryInterface $stockRepository, StockInterfaceFactory $stockFactory, + AssignSourcesToStockInterface $assignSourcesToStock, DataObjectHelper $dataObjectHelper ) { $this->sourceRepository = $sourceRepository; $this->sourceFactory = $sourceFactory; $this->stockRepository = $stockRepository; $this->stockFactory = $stockFactory; + $this->assignSourcesToStock = $assignSourcesToStock; $this->dataObjectHelper = $dataObjectHelper; } @@ -76,6 +85,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface { $this->addDefaultSource(); $this->addDefaultStock(); + $this->assignStockToSource(); } /** @@ -116,4 +126,14 @@ private function addDefaultStock() $this->dataObjectHelper->populateWithArray($source, $data, StockInterface::class); $this->stockRepository->save($source); } + + /** + * Assign default stock to default source + * + * @return void + */ + private function assignStockToSource() + { + $this->assignSourcesToStock->execute([1], 1); + } } diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php new file mode 100644 index 000000000000..b1bca75c82bd --- /dev/null +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php @@ -0,0 +1,42 @@ + [ + 'resourcePath' => '/V1/inventory/stock/get-assigned-sources/' . $defaultStockId, + 'httpMethod' => Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => 'inventoryApiGetAssignedSourcesForStockV1', + 'operation' => 'inventoryApiStockRepositoryV1Get', + ], + ]; + if (self::ADAPTER_REST == TESTS_WEB_API_ADAPTER) { + $source = $this->_webApiCall($serviceInfo); + } else { + $source = $this->_webApiCall($serviceInfo, ['stockId' => $defaultStockId]); + } + $this->assertEquals([$defaultSourceId], array_column($source, SourceInterface::SOURCE_ID)); + } +}