diff --git a/app/code/Magento/InventoryCatalog/Model/SourceItem/SourceItemsSave.php b/app/code/Magento/Inventory/Model/SourceItem/Command/Handler/SourceItemsSaveHandler.php similarity index 80% rename from app/code/Magento/InventoryCatalog/Model/SourceItem/SourceItemsSave.php rename to app/code/Magento/Inventory/Model/SourceItem/Command/Handler/SourceItemsSaveHandler.php index 6918445ce1e1..c52b2d813f8a 100644 --- a/app/code/Magento/InventoryCatalog/Model/SourceItem/SourceItemsSave.php +++ b/app/code/Magento/Inventory/Model/SourceItem/Command/Handler/SourceItemsSaveHandler.php @@ -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 @@ -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) { @@ -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); } diff --git a/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSave.php b/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSave.php index 722697dcf5cc..eedae47fd75d 100644 --- a/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSave.php +++ b/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSave.php @@ -7,13 +7,8 @@ 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 @@ -21,33 +16,16 @@ 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; } /** @@ -55,20 +33,6 @@ public function __construct( */ 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); } } diff --git a/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSaveWithoutLegacySynchronization.php b/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSaveWithoutLegacySynchronization.php new file mode 100644 index 000000000000..d44cfd96539c --- /dev/null +++ b/app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSaveWithoutLegacySynchronization.php @@ -0,0 +1,38 @@ +sourceItemsSaveHandler = $sourceItemsSaveHandler; + } + + /** + * @inheritdoc + */ + public function execute(array $sourceItems) + { + $this->sourceItemsSaveHandler->execute($sourceItems); + } +} diff --git a/app/code/Magento/InventoryCatalog/Model/UpdateSourceItemBasedOnLegacyStockItem.php b/app/code/Magento/InventoryCatalog/Model/UpdateSourceItemBasedOnLegacyStockItem.php index a1c1ca96e02d..476a01041e3a 100644 --- a/app/code/Magento/InventoryCatalog/Model/UpdateSourceItemBasedOnLegacyStockItem.php +++ b/app/code/Magento/InventoryCatalog/Model/UpdateSourceItemBasedOnLegacyStockItem.php @@ -62,7 +62,6 @@ class UpdateSourceItemBasedOnLegacyStockItem * @param DefaultSourceProviderInterface $defaultSourceProvider * @param ResourceConnection $resourceConnection * @param GetSkusByProductIdsInterface $getSkusByProductIds - */ public function __construct( SourceItemRepositoryInterface $sourceItemRepository, diff --git a/app/code/Magento/InventoryCatalog/composer.json b/app/code/Magento/InventoryCatalog/composer.json index f18c5ab0e3b4..2c9a85034e9c 100644 --- a/app/code/Magento/InventoryCatalog/composer.json +++ b/app/code/Magento/InventoryCatalog/composer.json @@ -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": [ diff --git a/app/code/Magento/InventoryCatalog/etc/di.xml b/app/code/Magento/InventoryCatalog/etc/di.xml index 2c1e3b77ac2e..91ccb8739d46 100644 --- a/app/code/Magento/InventoryCatalog/etc/di.xml +++ b/app/code/Magento/InventoryCatalog/etc/di.xml @@ -67,10 +67,10 @@ - Magento\InventoryCatalog\Model\SourceItem\SourceItemsSave + Magento\Inventory\Model\SourceItem\Command\SourceItemsSaveWithoutLegacySynchronization - + diff --git a/app/code/Magento/InventoryCatalog/etc/module.xml b/app/code/Magento/InventoryCatalog/etc/module.xml index 4d4841d54f9b..301fd1c00d82 100644 --- a/app/code/Magento/InventoryCatalog/etc/module.xml +++ b/app/code/Magento/InventoryCatalog/etc/module.xml @@ -6,9 +6,5 @@ */ --> - - - - - +