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

MSI: Slight refactoring #63

Merged
merged 1 commit into from
Aug 22, 2017
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 @@ -88,11 +88,11 @@ public function process($stockId, array $stockSourceLinksData)
}

if ($sourceIdsForSave) {
$this->assignSourcesToStock->execute($stockId, array_keys($sourceIdsForSave));
$this->assignSourcesToStock->execute(array_keys($sourceIdsForSave), $stockId);
}
if ($sourceIdsForDelete) {
foreach ($sourceIdsForDelete as $sourceIdForDelete) {
$this->unassignSourceFromStock->execute($stockId, $sourceIdForDelete);
$this->unassignSourceFromStock->execute($sourceIdForDelete, $stockId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
* @param array $sourceIds
* @return void
*/
public function execute($stockId, array $sourceIds)
public function execute(array $sourceIds, $stockId)
{
$connection = $this->connection->getConnection();
$tableName = $connection->getTableName(StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Inventory/Model/Source/Command/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function execute(SourceInterface $source)
$validationResult = $this->sourceValidator->validate($source);

if (!$validationResult->isValid()) {
throw new ValidationException($validationResult->getErrors());
throw new ValidationException($validationResult);
}

// TODO: check if exists?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Inventory\Model;
namespace Magento\Inventory\Model\SourceItem\Command;

use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\InputException;
use Magento\Inventory\Model\ResourceModel\SourceItem\SaveMultiple;
use Magento\InventoryApi\Api\SourceItemSaveInterface;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Psr\Log\LoggerInterface;

/**
* @inheritdoc
*/
class SourceItemSave implements SourceItemSaveInterface
class SourceItemsSave implements SourceItemsSaveInterface
{
/**
* @var SaveMultiple
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Inventory/Model/Stock/Command/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function execute(StockInterface $stock)
{
$validationResult = $this->stockValidator->validate($stock);
if (!$validationResult->isValid()) {
throw new ValidationException($validationResult->getErrors());
throw new ValidationException($validationResult);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Inventory\Model;
namespace Magento\Inventory\Model\StockSourceLink\Command;

use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\InputException;
Expand Down Expand Up @@ -41,13 +41,13 @@ public function __construct(
/**
* @inheritdoc
*/
public function execute($stockId, array $sourceIds)
public function execute(array $sourceIds, $stockId)
{
if (!is_numeric($stockId) || empty($sourceIds)) {
throw new InputException(__('Input data is invalid'));
}
try {
$this->saveMultiple->execute($stockId, $sourceIds);
$this->saveMultiple->execute($sourceIds, $stockId);
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
throw new CouldNotSaveException(__('Could not assign Sources to Stock'), $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Inventory\Model;
namespace Magento\Inventory\Model\StockSourceLink\Command;

use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Inventory\Model;
namespace Magento\Inventory\Model\StockSourceLink\Command;

use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
Expand Down Expand Up @@ -69,9 +69,9 @@ public function __construct(
/**
* @inheritdoc
*/
public function execute($stockId, $sourceId)
public function execute($sourceId, $stockId)
{
if (!is_numeric($stockId) || !is_numeric($sourceId)) {
if (!is_numeric($sourceId) || !is_numeric($stockId)) {
throw new InputException(__('Input data is invalid'));
}

Expand Down
14 changes: 7 additions & 7 deletions app/code/Magento/Inventory/Observer/SourceItemsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
use Magento\InventoryApi\Api\SourceItemSaveInterface;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;

/**
* At the time of processing Product save form this class used to save source items correctly
Expand Down Expand Up @@ -42,9 +42,9 @@ class SourceItemsProcessor
private $dataObjectHelper;

/**
* @var SourceItemSaveInterface
* @var SourceItemsSaveInterface
*/
private $sourceItemSave;
private $sourceItemsSave;

/**
* SourceItemsProcessor constructor
Expand All @@ -53,20 +53,20 @@ class SourceItemsProcessor
* @param SourceItemRepositoryInterface $sourceItemRepository
* @param SourceItemInterfaceFactory $sourceItemFactory
* @param DataObjectHelper $dataObjectHelper
* @param SourceItemSaveInterface $sourceItemSave
* @param SourceItemsSaveInterface $sourceItemsSave
*/
public function __construct(
SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
SourceItemRepositoryInterface $sourceItemRepository,
SourceItemInterfaceFactory $sourceItemFactory,
DataObjectHelper $dataObjectHelper,
SourceItemSaveInterface $sourceItemSave
SourceItemsSaveInterface $sourceItemsSave
) {
$this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
$this->sourceItemRepository = $sourceItemRepository;
$this->sourceItemFactory = $sourceItemFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->sourceItemSave = $sourceItemSave;
$this->sourceItemsSave = $sourceItemsSave;
}

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ public function process($sku, array $sourceItemsData)
unset($sourceItemsForDelete[$sourceId]);
}
if ($sourceItemsForSave) {
$this->sourceItemSave->execute($sourceItemsForSave);
$this->sourceItemsSave->execute($sourceItemsForSave);
}
if ($sourceItemsForDelete) {
$this->deleteSourceItems($sourceItemsForDelete);
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Inventory/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</type>
<!-- Source Item -->
<preference for="Magento\InventoryApi\Api\SourceItemRepositoryInterface" type="Magento\Inventory\Model\SourceItemRepository"/>
<preference for="Magento\InventoryApi\Api\SourceItemSaveInterface" type="Magento\Inventory\Model\SourceItemSave"/>
<preference for="Magento\InventoryApi\Api\SourceItemsSaveInterface" type="Magento\Inventory\Model\SourceItem\Command\SourceItemsSave"/>
<preference for="Magento\InventoryApi\Api\Data\SourceItemInterface" type="Magento\Inventory\Model\SourceItem"/>
<preference for="Magento\InventoryApi\Api\Data\SourceItemSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>
<preference for="Magento\Inventory\Model\SourceItem\Command\DeleteInterface" type="Magento\Inventory\Model\SourceItem\Command\Delete"/>
Expand Down Expand Up @@ -62,7 +62,7 @@
</arguments>
</type>
<!-- StockSourceLink -->
<preference for="Magento\InventoryApi\Api\AssignSourcesToStockInterface" type="Magento\Inventory\Model\AssignSourcesToStock"/>
<preference for="Magento\InventoryApi\Api\GetAssignedSourcesForStockInterface" type="Magento\Inventory\Model\GetAssignedSourcesForStock"/>
<preference for="Magento\InventoryApi\Api\UnassignSourceFromStockInterface" type="Magento\Inventory\Model\UnassignSourceFromStock"/>
<preference for="Magento\InventoryApi\Api\AssignSourcesToStockInterface" type="Magento\Inventory\Model\StockSourceLink\Command\AssignSourcesToStock"/>
<preference for="Magento\InventoryApi\Api\GetAssignedSourcesForStockInterface" type="Magento\Inventory\Model\StockSourceLink\Command\GetAssignedSourcesForStock"/>
<preference for="Magento\InventoryApi\Api\UnassignSourceFromStockInterface" type="Magento\Inventory\Model\StockSourceLink\Command\UnassignSourceFromStock"/>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ interface AssignSourcesToStockInterface
/**
* Assign source id list by stock id
*
* @param int $stockId
* @param int[] $sourceIds
* @param int $stockId
* @return void
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function execute($stockId, array $sourceIds);
public function execute(array $sourceIds, $stockId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\InventoryApi\Api;

/**
* Get assigned Sources for Stock command
* Get assigned Sources for Stock
*
* Used fully qualified namespaces in annotations for proper work of WebApi request parser
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* considered as SPI - Interfaces that you should extend and implement to customize current behaviour
*
* The method save is absent, due to different semantic (save multiple)
* @see SourceItemSaveInterface
* @see SourceItemsSaveInterface
*
* There is no get method because SourceItem identifies by compound identifier (sku and source_id),
* so need to use getList() method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @api
*/
interface SourceItemSaveInterface
interface SourceItemsSaveInterface
{
/**
* Save Multiple Source item data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\InventoryApi\Api;

/**
* Unassign source from stock command
* Unassign source from stock
*
* Used fully qualified namespaces in annotations for proper work of WebApi request parser
*
Expand All @@ -17,10 +17,10 @@ interface UnassignSourceFromStockInterface
/**
* Unassign source from stock
*
* @param int $stockId
* @param int $sourceId
* @param int $stockId
* @return void
* @throws \Magento\Framework\Exception\InputException
*/
public function execute($stockId, $sourceId);
public function execute($sourceId, $stockId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
class ValidationException extends AbstractAggregateException
{
/**
* @param array $errors
* @param ValidationResult $validationResult
* @param \Exception $cause
* @param int $code
*/
public function __construct(array $errors = [], \Exception $cause = null, $code = 0)
public function __construct(ValidationResult $validationResult, \Exception $cause = null, $code = 0)
{
foreach ($errors as $error) {
foreach ($validationResult->getErrors() as $error) {
$this->addError($error);
}
parent::__construct($this->phrase, $cause, $code);
Expand Down