Skip to content

Commit

Permalink
WIP MSI: magento#167
Browse files Browse the repository at this point in the history
- Add arround plugin listen to reservations append function
  • Loading branch information
larsroettig committed Oct 29, 2017
1 parent 307de4f commit dece474
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Created by PhpStorm.
* User: roettigl
* Date: 29.10.17
* Time: 15:24
*/

namespace Magento\InventoryCatalog\Plugin\Model;

use Magento\Framework\App\ResourceConnection;
use Magento\InventoryApi\Api\Data\ReservationInterface;
use Magento\InventoryApi\Api\ReservationsAppendInterface;

/**
* Plugin help to fill the legacy catalog inventory tables cataloginventory_stock_status and
* cataloginventory_stock_item to don't break the backward compatible.
*/
class LegacyCatalogInventoryPlugin
{

/**
* @var ResourceConnection
*/
private $resourceConnection;

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

/**
* Plugin method to fill the legacy tables.
*
* @param ReservationsAppendInterface $subject
* @param callable $callable
* @param ReservationInterface[] $reservations
* @return mixed
* @see ReservationsAppendInterface::execute
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(ReservationsAppendInterface $subject, callable $callable, array $reservations)
{
$result = $callable($reservations);
$this->updateStockItemTable($reservations);
$this->updateStockStatusTable($reservations);
return $result;
}

/**
* Update cataloginventory_stock_item qty with reservation information.
*
* @param ReservationInterface[] $reservations
* @return void
*/
private function updateStockItemTable(array $reservations)
{
// @todo impelemention reqiured
}

/**
* Update cataloginventory_stock_status qty with reservation information.
*
* @param ReservationInterface[] $reservations
* @return void
*/
private function updateStockStatusTable(array $reservations)
{
// @todo impelemention reqiured
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/InventoryCatalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<type name="Magento\InventoryApi\Api\StockRepositoryInterface">
<plugin name="prevent_default_stock_deletion" type="Magento\InventoryCatalog\Plugin\Model\StockRepositoryPlugin" sortOrder="1"/>
</type>
<type name="Magento\InventoryApi\Api\ReservationsAppendInterface">
<plugin name="legacy_catalog_inventory_plugin" type="Magento\InventoryCatalog\Plugin\Model\LegacyCatalogInventoryPlugin" sortOrder="1"/>
</type>
</config>

0 comments on commit dece474

Please sign in to comment.