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

Synchronization between sourceItem and stockItem deletion for defaultSourceId #269

Merged
merged 25 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
91ac8ac
Implemented plugins for updating legacy CatalogInventory data on sour…
sinisa86 Dec 12, 2017
fa3bf14
Modified synchronization plugins
sinisa86 Dec 12, 2017
a558f3d
Various fixes and API renames
sinisa86 Dec 12, 2017
11db553
Merge remote-tracking branch 'remotes/origin/develop' into delete_sou…
bartekszymanski Dec 15, 2017
2e3f0a5
Fix table names
bartekszymanski Dec 15, 2017
8e8535a
Fix table names
bartekszymanski Dec 15, 2017
b21c33e
Merge remote-tracking branch 'remotes/origin/develop' into delete_sou…
bartekszymanski Dec 15, 2017
794c7d0
Modified DeleteLegacyCatalogInventoryPlugin to update stockItem/stock…
sinisa86 Dec 15, 2017
453e724
fix products fixture
bartekszymanski Dec 15, 2017
e0d8a5e
Merge branch 'delete_source_items_stock_items_synchronization' of htt…
bartekszymanski Dec 15, 2017
71301d6
Fixed Static test issue in the DeleteTest
sinisa86 Dec 15, 2017
3e93be6
Merge remote-tracking branch 'remotes/origin/develop' into delete_sou…
bartekszymanski Dec 20, 2017
6c9a6a1
Skip functional test
bartekszymanski Dec 20, 2017
49ffa67
Synchronization between sourceItem and stockItem deletion for default…
bartekszymanski Dec 20, 2017
be62721
Synchronization between sourceItem and stockItem deletion for default…
bartekszymanski Dec 21, 2017
a9eb122
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
4a2f9c8
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
71d771a
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
a8d7081
Merge remote-tracking branch 'origin/develop' into delete_source_item…
Dec 21, 2017
c821d8c
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
52cf42b
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
a0a3380
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
71989ad
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
066b080
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 2017
ca6c78a
MSI: Synchronization between sourceItem and stockItem deletion for de…
Dec 21, 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
11 changes: 6 additions & 5 deletions app/code/Magento/InventoryApi/Test/_files/products.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
use Magento\InventoryApi\Api\SourceItemsDeleteInterface;
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface;
use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface;
use Magento\TestFramework\Helper\Bootstrap;

$objectManager = Bootstrap::getObjectManager();
Expand All @@ -39,7 +39,7 @@
'qty' => 0,
'is_in_stock' => false,
'manage_stock' => true
]
],
];

for ($i = 1; $i <= 3; $i++) {
Expand All @@ -60,16 +60,17 @@
if ($moduleManager->isEnabled('Magento_InventoryCatalog')) {
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
/** @var DefaultStockProviderInterface $defaultStockProvider */
$defaultStockProvider = $objectManager->get(DefaultStockProviderInterface::class);
/** @var DefaultSourceProviderInterface $defaultSourceProvider */
$defaultSourceProvider = $objectManager->get(DefaultSourceProviderInterface::class);
/** @var SourceItemRepositoryInterface $sourceItemRepository */
$sourceItemRepository = $objectManager->get(SourceItemRepositoryInterface::class);
/** @var SourceItemsDeleteInterface $sourceItemsDelete */
$sourceItemsDelete = $objectManager->get(SourceItemsDeleteInterface::class);

// Unassign created product from default Source
$searchCriteria = $searchCriteriaBuilder
->addFilter(SourceItemInterface::SKU, ['SKU-1', 'SKU-2', 'SKU-3'], 'in')
->addFilter(SourceItemInterface::SOURCE_ID, $defaultStockProvider->getId())
->addFilter(SourceItemInterface::SOURCE_ID, $defaultSourceProvider->getId())
->create();
$sourceItems = $sourceItemRepository->getList($searchCriteria)->getItems();
if (count($sourceItems)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
$registry->register('isSecureArea', true);

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

$result = $stockStatusRepository->getList($criteria);
$stockStatus = current($result->getItems());
$stockStatusRepository->delete($stockStatus);
if ($result->getTotalCount()) {
$stockStatus = current($result->getItems());
$stockStatusRepository->delete($stockStatus);
}

$productRepository->delete($product);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,40 @@
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Model;
namespace Magento\InventoryCatalog\Model\ResourceModel;

use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface;
use Magento\InventoryCatalog\Model\GetProductIdsBySkusInterface;

/**
* Update Legacy catalocinventory_stock_item database data
* Apply data to legacy catalocinventory_stock_item table via plain MySql query
*/
class UpdateLegacyStockItemByPlainQuery
class ApplyDataToLegacyStockItem
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var DefaultSourceProviderInterface
*/
private $defaultSourceProvider;

/**
* @var GetProductIdsBySkusInterface
*/
private $getProductIdsBySkus;

/**
* @param ResourceConnection $resourceConnection
* @param DefaultSourceProviderInterface $defaultSourceProvider
* @param GetProductIdsBySkusInterface $getProductIdsBySkus
*/
public function __construct(
ResourceConnection $resourceConnection,
DefaultSourceProviderInterface $defaultSourceProvider,
GetProductIdsBySkusInterface $getProductIdsBySkus
) {
$this->resourceConnection = $resourceConnection;
$this->defaultSourceProvider = $defaultSourceProvider;
$this->getProductIdsBySkus = $getProductIdsBySkus;
}

/**
* Execute Plain MySql query on catalaginventory_stock_item
*
* @param string $sku
* @param float $quantity
* @return void
Expand All @@ -64,7 +54,6 @@ public function execute(string $sku, float $quantity)
StockItemInterface::QTY => new \Zend_Db_Expr(sprintf('%s + %s', StockItemInterface::QTY, $quantity)),
],
[
StockItemInterface::STOCK_ID . ' = ?' => $this->defaultSourceProvider->getId(),
StockItemInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,40 @@
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Model;
namespace Magento\InventoryCatalog\Model\ResourceModel;

use Magento\CatalogInventory\Api\Data\StockStatusInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface;
use Magento\InventoryCatalog\Model\GetProductIdsBySkusInterface;

/**
* Update Legacy catalocinventory_stock_status database data
* Apply data to legacy cataloginventory_stock_status table via plain MySql query
*/
class UpdateLegacyStockStatusByPlainQuery
class ApplyDataToLegacyStockStatus
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var DefaultSourceProviderInterface
*/
private $defaultSourceProvider;

/**
* @var GetProductIdsBySkusInterface
*/
private $getProductIdsBySkus;

/**
* @param ResourceConnection $resourceConnection
* @param DefaultSourceProviderInterface $defaultSourceProvider
* @param GetProductIdsBySkusInterface $getProductIdsBySkus
*/
public function __construct(
ResourceConnection $resourceConnection,
DefaultSourceProviderInterface $defaultSourceProvider,
GetProductIdsBySkusInterface $getProductIdsBySkus
) {
$this->resourceConnection = $resourceConnection;
$this->defaultSourceProvider = $defaultSourceProvider;
$this->getProductIdsBySkus = $getProductIdsBySkus;
}

/**
* Execute Plain MySql query on catalaginventory_stock_status
*
* @param string $sku
* @param float $quantity
* @return void
Expand All @@ -64,7 +54,6 @@ public function execute(string $sku, float $quantity)
StockStatusInterface::QTY => new \Zend_Db_Expr(sprintf('%s + %s', StockStatusInterface::QTY, $quantity))
],
[
StockStatusInterface::STOCK_ID . ' = ?' => $this->defaultSourceProvider->getId(),
StockStatusInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0,
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Model\ResourceModel;

use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\InventoryCatalog\Model\GetProductIdsBySkusInterface;

/**
* Set data to legacy catalocinventory_stock_item table via plain MySql query
*/
class SetDataToLegacyStockItem
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var GetProductIdsBySkusInterface
*/
private $getProductIdsBySkus;

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

/**
* @param string $sku
* @param float $quantity
* @param int $status
* @return void
*/
public function execute(string $sku, float $quantity, int $status)
{
$productId = $this->getProductIdsBySkus->execute([$sku])[$sku];

$connection = $this->resourceConnection->getConnection();
$connection->update(
$this->resourceConnection->getTableName('cataloginventory_stock_item'),
[
StockItemInterface::IS_IN_STOCK => $status,
StockItemInterface::QTY => $quantity,
],
[
StockItemInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0,
]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Model\ResourceModel;

use Magento\CatalogInventory\Api\Data\StockStatusInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\InventoryCatalog\Model\GetProductIdsBySkusInterface;

/**
* Set data to legacy cataloginventory_stock_status table via plain MySql query
*/
class SetDataToLegacyStockStatus
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var GetProductIdsBySkusInterface
*/
private $getProductIdsBySkus;

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

/**
* @param string $sku
* @param float $quantity
* @param int $status
* @return void
*/
public function execute(string $sku, float $quantity, int $status)
{
$productId = $this->getProductIdsBySkus->execute([$sku])[$sku];

$connection = $this->resourceConnection->getConnection();
$connection->update(
$this->resourceConnection->getTableName('cataloginventory_stock_status'),
[
StockStatusInterface::STOCK_STATUS => $status,
StockStatusInterface::QTY => $quantity,
],
[
StockStatusInterface::PRODUCT_ID . ' = ?' => $productId,
'website_id = ?' => 0,
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Class provides around Plugin on \Magento\CatalogInventory\Model\ResourceModel\Stock\Item::save
* to update data in Inventory source item based on legacy Stock Item data
*/
class UpdateSourceItemAtLegacyStockSettingPlugin
class UpdateSourceItemAtLegacyStockItemSavePlugin
{
/**
* @var SourceItemRepositoryInterface
Expand Down
Loading