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

Create Index (table) for Default Stock after Inventory module is installed #122

Merged
merged 5 commits into from
Oct 6, 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
16 changes: 14 additions & 2 deletions app/code/Magento/InventoryCatalog/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Inventory\Indexer\StockItemIndexerInterface;
use Magento\InventoryApi\Api\Data\SourceInterfaceFactory;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
Expand All @@ -22,6 +23,8 @@

/**
* Install Default Source, Stock and link them together
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class InstallData implements InstallDataInterface
{
Expand Down Expand Up @@ -55,6 +58,11 @@ class InstallData implements InstallDataInterface
*/
private $assignSourcesToStock;

/**
* @var StockItemIndexerInterface
*/
private $stockItemIndexer;

/**
* @var DefaultSourceProviderInterface
*/
Expand All @@ -72,6 +80,7 @@ class InstallData implements InstallDataInterface
* @param StockInterfaceFactory $stockFactory
* @param AssignSourcesToStockInterface $assignSourcesToStock
* @param DataObjectHelper $dataObjectHelper
* @param StockItemIndexerInterface $stockItemIndexer
* @param DefaultSourceProviderInterface $defaultSourceProvider
* @param DefaultStockProviderInterface $defaultStockProvider
*/
Expand All @@ -82,6 +91,7 @@ public function __construct(
StockInterfaceFactory $stockFactory,
AssignSourcesToStockInterface $assignSourcesToStock,
DataObjectHelper $dataObjectHelper,
StockItemIndexerInterface $stockItemIndexer,
DefaultSourceProviderInterface $defaultSourceProvider,
DefaultStockProviderInterface $defaultStockProvider
) {
Expand All @@ -91,6 +101,7 @@ public function __construct(
$this->stockFactory = $stockFactory;
$this->assignSourcesToStock = $assignSourcesToStock;
$this->dataObjectHelper = $dataObjectHelper;
$this->stockItemIndexer = $stockItemIndexer;
$this->defaultSourceProvider = $defaultSourceProvider;
$this->defaultStockProvider = $defaultStockProvider;
}
Expand All @@ -103,7 +114,8 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
{
$this->addDefaultSource();
$this->addDefaultStock();
$this->assignStockToSource();
$this->assignSourceToStock();
$this->stockItemIndexer->executeFull();
}

/**
Expand Down Expand Up @@ -150,7 +162,7 @@ private function addDefaultStock()
*
* @return void
*/
private function assignStockToSource()
private function assignSourceToStock()
{
$this->assignSourcesToStock->execute(
[$this->defaultSourceProvider->getId()],
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/InventoryCatalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\InventoryCatalog\Api\DefaultStockResolverInterface" type="Magento\InventoryCatalog\Model\DefaultStockResolver"/>
<preference for="Magento\InventoryCatalog\Api\DefaultSourceResolverInterface" type="Magento\InventoryCatalog\Model\DefaultSourceResolver"/>
<preference for="Magento\InventoryCatalog\Api\DefaultStockProviderInterface" type="Magento\InventoryCatalog\Model\DefaultStockProvider"/>
<preference for="Magento\InventoryCatalog\Api\DefaultSourceProviderInterface" type="Magento\InventoryCatalog\Model\DefaultSourceProvider"/>
</config>