-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruslan
committed
Dec 14, 2017
1 parent
7fbffe6
commit d28054c
Showing
13 changed files
with
719 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...nto/InventoryCatalog/Plugin/CatalogInventory/DeleteSourceItemsAtLegacyStockItemDelete.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Plugin\CatalogInventory; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\CatalogInventory\Api\Data\StockItemInterface; | ||
use Magento\CatalogInventory\Model\Stock\StockItemRepository; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Framework\Exception\InputException; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\SourceItemRepositoryInterface; | ||
use Magento\InventoryApi\Api\SourceItemsDeleteInterface; | ||
use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; | ||
|
||
/** | ||
* Class provides around Plugin on Magento\CatalogInventory\Model\ResourceModel\Stock\Item::delete | ||
* to update data in Inventory source item | ||
*/ | ||
class DeleteSourceItemsAtLegacyStockItemDelete | ||
{ | ||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
|
||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @var SourceItemRepositoryInterface | ||
*/ | ||
private $sourceItemRepository; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var SourceItemsDeleteInterface | ||
*/ | ||
private $sourceItemsDelete; | ||
/** | ||
* @var DefaultSourceProviderInterface | ||
*/ | ||
private $defaultSourceProvider; | ||
|
||
/** | ||
* @param ProductRepositoryInterface $productRepository | ||
* @param ResourceConnection $resourceConnection | ||
* @param SourceItemRepositoryInterface $sourceItemRepository | ||
* @param SourceItemsDeleteInterface $sourceItemsDelete | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param DefaultSourceProviderInterface $defaultSourceProvider | ||
*/ | ||
public function __construct( | ||
ProductRepositoryInterface $productRepository, | ||
ResourceConnection $resourceConnection, | ||
SourceItemRepositoryInterface $sourceItemRepository, | ||
SourceItemsDeleteInterface $sourceItemsDelete, | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
DefaultSourceProviderInterface $defaultSourceProvider | ||
) { | ||
$this->productRepository = $productRepository; | ||
$this->resourceConnection = $resourceConnection; | ||
$this->sourceItemRepository = $sourceItemRepository; | ||
$this->sourceItemsDelete = $sourceItemsDelete; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->defaultSourceProvider = $defaultSourceProvider; | ||
} | ||
|
||
/** | ||
* @param StockItemRepository $subject | ||
* @param callable $proceed | ||
* @param StockItemInterface $stockItem | ||
* | ||
* @return void | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function aroundDelete(StockItemRepository $subject, callable $proceed, StockItemInterface $stockItem) | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$connection->beginTransaction(); | ||
|
||
try { | ||
$proceed($stockItem); | ||
|
||
$product = $this->productRepository->getById($stockItem->getProductId()); | ||
$searchCriteria = $this->searchCriteriaBuilder | ||
->addFilter(SourceItemInterface::SKU, $product->getSku()) | ||
->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) | ||
->create(); | ||
$sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); | ||
|
||
$this->sourceItemsDelete->execute($sourceItems); | ||
$connection->commit(); | ||
} catch (CouldNotSaveException $e) { | ||
$connection->rollBack(); | ||
} catch (InputException $e) { | ||
$connection->rollBack(); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/code/Magento/InventoryCatalog/Plugin/InventoryApi/DeleteLegacyCatalogInventoryPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Plugin\InventoryApi; | ||
|
||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\SourceItemsDeleteInterface; | ||
use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; | ||
use Magento\InventoryCatalog\Model\DeleteLegacyStockItemByDefaultSourceItem; | ||
use Magento\InventoryCatalog\Model\DeleteLegacyStockStatusByDefaultSourceItem; | ||
|
||
/** | ||
* Plugin help to delete related entries from the legacy catalog inventory tables cataloginventory_stock_status and | ||
* cataloginventory_stock_item if deleted source item is default source item. | ||
*/ | ||
class DeleteLegacyCatalogInventoryPlugin | ||
{ | ||
/** | ||
* @var DefaultSourceProviderInterface | ||
*/ | ||
private $defaultSourceProvider; | ||
|
||
/** | ||
* @var DeleteLegacyStockItemByDefaultSourceItem | ||
*/ | ||
private $deleteStockItemBySourceItem; | ||
|
||
/** | ||
* @var DeleteLegacyStockStatusByDefaultSourceItem | ||
*/ | ||
private $deleteStockStatusBySourceItem; | ||
|
||
/** | ||
* @param DefaultSourceProviderInterface $defaultSourceProvider | ||
* @param DeleteLegacyStockItemByDefaultSourceItem $deleteStockItemBySourceItem | ||
* @param DeleteLegacyStockStatusByDefaultSourceItem $deleteStockStatusBySourceItem | ||
*/ | ||
public function __construct( | ||
DefaultSourceProviderInterface $defaultSourceProvider, | ||
DeleteLegacyStockItemByDefaultSourceItem $deleteStockItemBySourceItem, | ||
DeleteLegacyStockStatusByDefaultSourceItem $deleteStockStatusBySourceItem | ||
) { | ||
$this->defaultSourceProvider = $defaultSourceProvider; | ||
$this->deleteStockItemBySourceItem = $deleteStockItemBySourceItem; | ||
$this->deleteStockStatusBySourceItem = $deleteStockStatusBySourceItem; | ||
} | ||
|
||
/** | ||
* Plugin method to delete entry from the legacy tables. | ||
* | ||
* @param SourceItemsDeleteInterface $subject | ||
* @param void $result | ||
* @param SourceItemInterface[] $sourceItems | ||
* | ||
* @see SourceItemsDeleteInterface::execute | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* @return void | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function afterExecute(SourceItemsDeleteInterface $subject, $result, array $sourceItems) | ||
{ | ||
$defaultSourceId = $this->defaultSourceProvider->getId(); | ||
|
||
foreach ($sourceItems as $sourceItem) { | ||
if ($sourceItem->getSourceId() == $defaultSourceId) { | ||
$this->deleteStockItemBySourceItem->execute($sourceItem); | ||
$this->deleteStockStatusBySourceItem->execute($sourceItem); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.