Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linkage between Default Source and Stock #118

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/code/Magento/InventoryCatalog/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -47,24 +48,32 @@ 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(
SourceRepositoryInterface $sourceRepository,
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;
}

Expand All @@ -76,6 +85,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
{
$this->addDefaultSource();
$this->addDefaultStock();
$this->assignStockToSource();
}

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\InventoryCatalog\Test\Api;

use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Framework\Webapi\Rest\Request;

/**
* Class GetDefaultStockToSourceLinkTest
*/
class GetDefaultStockToSourceLinkTest extends WebapiAbstract
{
/**
* Test that default Stock is present after installation
*/
public function testGetDefaultStockToSourceLink()
{
$defaultStockId = 1;
$defaultSourceId = 1;
$serviceInfo = [
'rest' => [
'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));
}
}