Skip to content

Fix hard dependency of InventoryCatalog on Inventory module #1168

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Model\SourceItem;
namespace Magento\Inventory\Model\SourceItem\Command\Handler;

use Exception;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Validation\ValidationException;
use Magento\Inventory\Model\ResourceModel\SourceItem\SaveMultiple;
use Magento\Inventory\Model\SourceItem\Validator\SourceItemsValidator;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Psr\Log\LoggerInterface;

/**
* @inheritdoc
* Class SourceItemsSaveHandler
*/
class SourceItemsSave implements SourceItemsSaveInterface
class SourceItemsSaveHandler
{
/**
* @var SourceItemsValidator
Expand Down Expand Up @@ -51,7 +52,13 @@ public function __construct(
}

/**
* @inheritdoc
* Save Multiple Source item data
*
* @param SourceItemInterface[] $sourceItems
* @return void
* @throws InputException
* @throws ValidationException
* @throws CouldNotSaveException
*/
public function execute(array $sourceItems)
{
Expand All @@ -66,7 +73,7 @@ public function execute(array $sourceItems)

try {
$this->saveMultiple->execute($sourceItems);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->error($e->getMessage());
throw new CouldNotSaveException(__('Could not save Source Item'), $e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,32 @@

namespace Magento\Inventory\Model\SourceItem\Command;

use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Validation\ValidationException;
use Magento\Inventory\Model\ResourceModel\SourceItem\SaveMultiple;
use Magento\Inventory\Model\SourceItem\Validator\SourceItemsValidator;
use Magento\Inventory\Model\SourceItem\Command\Handler\SourceItemsSaveHandler;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Psr\Log\LoggerInterface;

/**
* @inheritdoc
*/
class SourceItemsSave implements SourceItemsSaveInterface
{
/**
* @var SourceItemsValidator
* @var SourceItemsSaveHandler
*/
private $sourceItemsValidator;
private $sourceItemsSaveHandler;

/**
* @var SaveMultiple
* @param SourceItemsSaveHandler $sourceItemsSaveHandler
*/
private $saveMultiple;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param SourceItemsValidator $sourceItemsValidator
* @param SaveMultiple $saveMultiple
* @param LoggerInterface $logger
*/
public function __construct(
SourceItemsValidator $sourceItemsValidator,
SaveMultiple $saveMultiple,
LoggerInterface $logger
) {
$this->sourceItemsValidator = $sourceItemsValidator;
$this->saveMultiple = $saveMultiple;
$this->logger = $logger;
public function __construct(SourceItemsSaveHandler $sourceItemsSaveHandler)
{
$this->sourceItemsSaveHandler = $sourceItemsSaveHandler;
}

/**
* @inheritdoc
*/
public function execute(array $sourceItems)
{
if (empty($sourceItems)) {
throw new InputException(__('Input data is empty'));
}

$validationResult = $this->sourceItemsValidator->validate($sourceItems);
if (!$validationResult->isValid()) {
throw new ValidationException(__('Validation Failed'), null, 0, $validationResult);
}

try {
$this->saveMultiple->execute($sourceItems);
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
throw new CouldNotSaveException(__('Could not save Source Item'), $e);
}
$this->sourceItemsSaveHandler->execute($sourceItems);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Inventory\Model\SourceItem\Command;

use Magento\Inventory\Model\SourceItem\Command\Handler\SourceItemsSaveHandler;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;

/**
* @inheritdoc
*/
class SourceItemsSaveWithoutLegacySynchronization implements SourceItemsSaveInterface
{
/**
* @var SourceItemsSaveHandler
*/
private $sourceItemsSaveHandler;

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

/**
* @inheritdoc
*/
public function execute(array $sourceItems)
{
$this->sourceItemsSaveHandler->execute($sourceItems);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class UpdateSourceItemBasedOnLegacyStockItem
* @param DefaultSourceProviderInterface $defaultSourceProvider
* @param ResourceConnection $resourceConnection
* @param GetSkusByProductIdsInterface $getSkusByProductIds

*/
public function __construct(
SourceItemRepositoryInterface $sourceItemRepository,
Expand Down
5 changes: 2 additions & 3 deletions app/code/Magento/InventoryCatalog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
"magento/framework": "*",
"magento/module-catalog": "*",
"magento/module-catalog-inventory": "*",
"magento/module-inventory": "*",
"magento/module-inventory-api": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-store": "*",
"magento/module-inventory": "*",
"magento/module-inventory-configuration-api": "*",
"magento/module-inventory-indexer": "*",
"magento/module-inventory-sales-api": "*"
},
"suggest": {
"magento/module-inventory-reservations-api": "*",
"magento/module-inventory": "*"
"magento/module-inventory-reservations-api": "*"
},
"type": "magento2-module",
"license": [
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 @@ -67,10 +67,10 @@
</type>
<type name="Magento\InventoryCatalog\Model\UpdateSourceItemBasedOnLegacyStockItem">
<arguments>
<argument name="sourceItemsSave" xsi:type="object">Magento\InventoryCatalog\Model\SourceItem\SourceItemsSave</argument>
<argument name="sourceItemsSave" xsi:type="object">Magento\Inventory\Model\SourceItem\Command\SourceItemsSaveWithoutLegacySynchronization</argument>
</arguments>
</type>
<type name="Magento\InventoryCatalog\Model\SourceItem\SourceItemsSave">
<type name="Magento\Inventory\Model\SourceItem\Command\SourceItemsSaveWithoutLegacySynchronization">
<plugin name="set_data_to_legacy_catalog_inventory_at_source_items_save" disabled="true"/>
</type>
</config>
6 changes: 1 addition & 5 deletions app/code/Magento/InventoryCatalog/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_InventoryCatalog" setup_version="1.0.0" >
<sequence>
<module name="Magento_Inventory"/>
</sequence>
</module>
<module name="Magento_InventoryCatalog" setup_version="1.0.0" />
</config>