Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e709586
Migrate Single Stock Data From CatalogInventory to MSI SourceItems
bartekszymanski Nov 9, 2017
79a26c3
Merge remote-tracking branch 'remotes/origin/develop' into migrate-si…
bartekszymanski Nov 14, 2017
c390c2b
Migrate Single Stock Data From CatalogInventory to MSI SourceItems - …
bartekszymanski Nov 15, 2017
d85d7a6
Migrate Single Stock Data From CatalogInventory to MSI SourceItems
bartekszymanski Nov 21, 2017
86f3ae9
Merge branch 'install-data-code-quality' into migrate-single-stock-data
bartekszymanski Nov 21, 2017
a371305
Migrate Single Stock Data From CatalogInventory to MSI SourceItems
bartekszymanski Nov 21, 2017
cc3e005
misspelling in namespace
bartekszymanski Nov 21, 2017
b19fcdb
misspelling in namespace
bartekszymanski Nov 21, 2017
f33d780
Merge remote-tracking branch 'origin/develop' into migrate-single-sto…
Nov 23, 2017
8b0631f
Migrate Single Stock Data Fix from CR
bartekszymanski Nov 24, 2017
03c1894
change single delete to mass delete on source_items_rollback
bartekszymanski Nov 24, 2017
210ede2
and webiste 0 to plain sql, format, remove unused plugin
bartekszymanski Nov 24, 2017
c870ecb
add strict types
bartekszymanski Nov 24, 2017
21c9661
legacy update
bartekszymanski Nov 24, 2017
92f6f15
add dependency in InventorySales on InventoryCatalog
bartekszymanski Nov 24, 2017
e3560f2
add dependency in InventorySales on InventoryCatalog
bartekszymanski Nov 24, 2017
6765e91
Merge remote-tracking branch 'remotes/origin/develop' into migrate-si…
bartekszymanski Nov 28, 2017
fe12129
Source Item Indexer Test
bartekszymanski Dec 4, 2017
f9d16df
Merge remote-tracking branch 'remotes/origin/develop' into migrate-si…
bartekszymanski Dec 4, 2017
1831fd9
update plugin
bartekszymanski Dec 5, 2017
cd18e4b
add "@magentoapparea adminhtml" to all tests which are used with Inve…
bartekszymanski Dec 6, 2017
2e2c859
CR fix
bartekszymanski Dec 7, 2017
8662810
CR fix
bartekszymanski Dec 7, 2017
4fee1e9
plugin for QtyCounter
bartekszymanski Dec 8, 2017
48cf313
Merge remote-tracking branch 'remotes/origin/develop' into migrate-si…
bartekszymanski Dec 8, 2017
e8854f4
plain sql change
bartekszymanski Dec 8, 2017
84caf5e
plain sql change
bartekszymanski Dec 8, 2017
cd6c564
CR
bartekszymanski Dec 8, 2017
c56a3c3
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 8, 2017
9f5b2bb
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 8, 2017
4afe202
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 8, 2017
59820d7
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 8, 2017
b7fe73d
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
bartekszymanski Dec 9, 2017
ef4ec1f
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
bartekszymanski Dec 9, 2017
6c96461
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
bartekszymanski Dec 9, 2017
f47b058
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 9, 2017
0fb47e6
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 9, 2017
9d1dd8b
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 9, 2017
baa2d7d
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 9, 2017
704020a
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 9, 2017
85fc59e
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 10, 2017
1bd31b1
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 10, 2017
6fa12c0
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 10, 2017
61de984
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 10, 2017
e2465cb
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 10, 2017
3e6bae0
MSI: Migrate Single Stock Data From CatalogInventory to MSI SourceItems
Dec 11, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Test\Integration\Indexer;

use Magento\Framework\App\ResourceConnection;
use Magento\Inventory\Model\ResourceModel\SourceItem as SourceItemResourceModel;
use Magento\InventoryApi\Api\Data\SourceItemInterface;

class GetSourceItemId
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @param ResourceConnection $resourceConnection
*/
public function __construct(ResourceConnection $resourceConnection)
{
$this->resourceConnection = $resourceConnection;
}

/**
* @param string $sku
* @param int $sourceId
* @return int
*/
public function execute(string $sku, int $sourceId): int
{
$connection = $this->resourceConnection->getConnection();
$select = $connection->select()
->from(
$this->resourceConnection->getTableName(SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM),
[SourceItemResourceModel::ID_FIELD_NAME]
)
->where(SourceItemInterface::SKU . ' = ?', $sku)
->where(SourceItemInterface::SOURCE_ID . ' = ?', $sourceId);

return (int)$connection->fetchOne($select);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class SourceIndexerTest extends TestCase
*/
private $removeIndexData;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->indexer = Bootstrap::getObjectManager()->get(IndexerInterface::class);
Expand All @@ -42,6 +45,9 @@ protected function setUp()
$this->removeIndexData->execute([10, 20, 30]);
}

/**
* {@inheritdoc}
*/
public function tearDown()
{
$this->removeIndexData->execute([10, 20, 30]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class SourceItemIndexerTest extends TestCase
*/
private $removeIndexData;

/**
* @var GetSourceItemId
*/
private $getSourceItemId;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->indexer = Bootstrap::getObjectManager()->get(IndexerInterface::class);
Expand All @@ -40,8 +48,13 @@ protected function setUp()

$this->removeIndexData = Bootstrap::getObjectManager()->get(RemoveIndexData::class);
$this->removeIndexData->execute([10, 20, 30]);

$this->getSourceItemId = Bootstrap::getObjectManager()->get(GetSourceItemId::class);
}

/**
* {@inheritdoc}
*/
public function tearDown()
{
$this->removeIndexData->execute([10, 20, 30]);
Expand All @@ -56,7 +69,7 @@ public function tearDown()
*/
public function testReindexRow()
{
$this->indexer->reindexRow(1);
$this->indexer->reindexRow($this->getSourceItemId->execute('SKU-1', 10));

self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10));
self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30));
Expand All @@ -71,7 +84,10 @@ public function testReindexRow()
*/
public function testReindexList()
{
$this->indexer->reindexList([1, 5]);
$this->indexer->reindexList([
$this->getSourceItemId->execute('SKU-1', 10),
$this->getSourceItemId->execute('SKU-2', 50),
]);

self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10));
self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class StockIndexerTest extends TestCase
*/
private $removeIndexData;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->indexer = Bootstrap::getObjectManager()->get(IndexerInterface::class);
Expand All @@ -42,6 +45,9 @@ protected function setUp()
$this->removeIndexData->execute([10, 20, 30]);
}

/**
* {@inheritdoc}
*/
public function tearDown()
{
$this->removeIndexData->execute([10, 20, 30]);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class GetProductQuantityInStockTest extends TestCase
*/
private $removeIndexData;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->indexer = Bootstrap::getObjectManager()->create(IndexerInterface::class);
Expand All @@ -66,6 +69,9 @@ protected function setUp()
$this->removeIndexData->execute([10]);
}

/**
* {@inheritdoc}
*/
public function tearDown()
{
$this->removeIndexData->execute([10]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class IsProductInStockTest extends TestCase
*/
private $removeIndexData;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->indexer = Bootstrap::getObjectManager()->create(IndexerInterface::class);
Expand All @@ -63,6 +66,9 @@ protected function setUp()
$this->removeIndexData->execute([10]);
}

/**
* {@inheritdoc}
*/
public function tearDown()
{
$this->removeIndexData->execute([10]);
Expand Down
31 changes: 31 additions & 0 deletions app/code/Magento/InventoryApi/Test/_files/products.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Catalog\Api\Data\ProductInterfaceFactory;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Type;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Module\Manager;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
use Magento\InventoryApi\Api\SourceItemsDeleteInterface;
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface;
use Magento\TestFramework\Helper\Bootstrap;

$objectManager = Bootstrap::getObjectManager();
Expand Down Expand Up @@ -45,3 +53,26 @@
->setStatus(Status::STATUS_ENABLED);
$productRepository->save($product);
}

/** @var Manager $moduleManager */
$moduleManager = Bootstrap::getObjectManager()->get(Manager::class);
// soft dependency in tests because we don't have possibility replace fixture from different modules
if ($moduleManager->isEnabled('Magento_InventoryCatalog')) {
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
/** @var DefaultStockProviderInterface $defaultStockProvider */
$defaultStockProvider = $objectManager->get(DefaultStockProviderInterface::class);
/** @var SourceItemRepositoryInterface $sourceItemRepository */
$sourceItemRepository = $objectManager->get(SourceItemRepositoryInterface::class);
/** @var SourceItemsDeleteInterface $sourceItemsDelete */
$sourceItemsDelete = $objectManager->get(SourceItemsDeleteInterface::class);

$searchCriteria = $searchCriteriaBuilder
->addFilter(SourceItemInterface::SKU, ['SKU-1', 'SKU-2', 'SKU-3'], 'in')
->addFilter(SourceItemInterface::SOURCE_ID, $defaultStockProvider->getId())
->create();
$sourceItems = $sourceItemRepository->getList($searchCriteria)->getItems();
if (count($sourceItems)) {
$sourceItemsDelete->execute($sourceItems);
}
}
48 changes: 33 additions & 15 deletions app/code/Magento/InventoryApi/Test/_files/products_rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory;
use Magento\CatalogInventory\Api\StockStatusRepositoryInterface;
use Magento\Framework\Registry;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Catalog\Api\Data\ProductInterface;

$objectManager = Bootstrap::getObjectManager();
/** @var ProductRepositoryInterface $productRepository */
Expand All @@ -19,22 +23,36 @@
/** @var StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory */
$stockStatusCriteriaFactory = $objectManager->create(StockStatusCriteriaInterfaceFactory::class);

$currentArea = $registry->registry('isSecureArea');
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
$searchCriteria = $searchCriteriaBuilder->addFilter(
ProductInterface::SKU,
['SKU-1', 'SKU-2', 'SKU-3'],
'in'
)->create();
$products = $productRepository->getList($searchCriteria)->getItems();

/**
* Tests which are wrapped with MySQL transaction clear all data by transaction rollback.
* In that case there is "if" which checks that SKU1, SKU2 and SKU3 still exists in database.
*/
if (!empty($products)) {
$currentArea = $registry->registry('isSecureArea');
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);

foreach ($products as $product) {
/** @var \Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory */
$criteria = $stockStatusCriteriaFactory->create();
$criteria->setProductsFilter($product->getId());

for ($i = 1; $i <= 3; $i++) {
$product = $productRepository->get('SKU-' . $i);
/** @var \Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory **/
$criteria = $stockStatusCriteriaFactory->create();
$criteria->setProductsFilter($product->getId());
$result = $stockStatusRepository->getList($criteria);
$stockStatus = current($result->getItems());
$stockStatusRepository->delete($stockStatus);

$result = $stockStatusRepository->getList($criteria);
$stockStatus = current($result->getItems());
$stockStatusRepository->delete($stockStatus);
$productRepository->delete($product);
}

$productRepository->deleteById('SKU-' . $i);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', $currentArea);
}

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', $currentArea);
8 changes: 2 additions & 6 deletions app/code/Magento/InventoryApi/Test/_files/source_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Api\DataObjectHelper;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\App\ResourceConnection;

/** @var DataObjectHelper $dataObjectHelper */
$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
Expand Down Expand Up @@ -58,11 +59,6 @@
],
];

$resourceConnection = Bootstrap::getObjectManager()->get(ResourceConnection::class);
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
$connection = $resourceConnection->getConnection();
$connection->query('ALTER TABLE ' . $resourceConnection->getTableName('inventory_source_item') . ' AUTO_INCREMENT 1;');

$sourceItems = [];
foreach ($sourcesItemsData as $sourceItemData) {
/** @var SourceItemInterface $source */
Expand Down
Loading