Conversation
source item management
| $connection, | ||
| $resource | ||
| ); | ||
| } |
There was a problem hiding this comment.
do we really need to have this constructor if all that it does is just proxying input parameters to parent constructor
| public function setStatus($status) | ||
| { | ||
| $this->setData(SourceItemInterface::STATUS, $status); | ||
| } |
There was a problem hiding this comment.
we also need to have next methods in this interface and implementation
getExtensionAttributes()/
setExtensionAttributes(\Magento\InventoryApi\Api\Data\SourceItemExtensionInterface $extensionAttributes)
| * @param bool $status | ||
| * @return void | ||
| */ | ||
| public function setStatus($status); |
There was a problem hiding this comment.
getExtensionAttributes()/
setExtensionAttributes(\Magento\InventoryApi\Api\Data\SourceItemExtensionInterface $extensionAttributes)
| /** | ||
| * Get source item status. | ||
| * | ||
| * @return bool |
There was a problem hiding this comment.
let's make status as INT
it will help us to reserve possible different statuses except "In STOCK" and "Out of Stock" if we will get some other statuses in future
| * Constants for status value. | ||
| */ | ||
| const IS_IN_STOCK = TRUE; | ||
| const IS_OUT_OF_STOCK = FALSE; |
There was a problem hiding this comment.
let's make values of these constants as 0 and 1
| * on getList method, because entity loading way is different for these methods | ||
| * | ||
| * @param \Magento\InventoryApi\Api\Data\SourceItemInterface $sourceItem | ||
| * @return int |
There was a problem hiding this comment.
return type should be void, not int
|
|
||
| use Magento\Framework\Api\ExtensibleDataInterface; | ||
|
|
||
| interface SourceItemInterface extends ExtensibleDataInterface |
There was a problem hiding this comment.
Let's add a description what's SourceItem interface represents. i.e. amount of particular product on some particular physical storage.
Also, let's add the description to the SourceInterface
| * @return int | ||
| * @throws \Magento\Framework\Exception\CouldNotSaveException | ||
| */ | ||
| public function save(\Magento\InventoryApi\Api\Data\SourceItemInterface $sourceItem); |
There was a problem hiding this comment.
let's make this method to accept an array of SourceItems in other case Repository::save would be performance bottleneck, because this method usually used for syncronization with ERP system and should be high performant.
So, bulk operation should be supported
There was a problem hiding this comment.
but it's not clear how to handle multiple statuses, we don't have dedicated interfaces which return statuses for Bulk API.
Like source item IDs 1,2,3,5 saved sucessfully
4 and 6 are failed to save.
Will raise this question on Architectural meeting
There was a problem hiding this comment.
@maghamed but than we need some bulk save function the following code have also the same e performance bottleneck. We can discuss this in an architectural call.
/**
* @inheritdoc
*/
public function save(array $sourceItemList)
{
try {
$savedSourceItems = [];
foreach ($sourceItemList as $sourceItem)
{
$this->resourceSource->save($sourceItem);
$savedItems[] = $sourceItem->getSourceItemId();
}
return $savedSourceItems;
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
throw new CouldNotSaveException(__('Could not save source item'), $e);
}
}
There was a problem hiding this comment.
I draf some posbile methode
/**
* @param SourceItemInterface[] $sourceItemList
* @return [] list of saved
*/
public function multiSave(array $sourceItemList)
{
$sourceItemData = [];
foreach ($sourceItemList as $sourceItem) {
$sourceItemData[] = [
SourceItemInterface::SKU => $sourceItem->getSku(),
SourceItemInterface::QUANTITY => $sourceItem->getQuantity(),
/** @todo only a draft */
];
}
$connection = $this->connection->getConnection();
$connection->insertMultiple(
$connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_ITEM),
$sourceItemData
);
}
| * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria | ||
| * @return \Magento\InventoryApi\Api\Data\SourceItemSearchResultsInterface | ||
| */ | ||
| public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null); |
There was a problem hiding this comment.
this search criteria should not be nullable.
There was a problem hiding this comment.
why not for SourceRepository it is also nullable?
…rce-item-management # Conflicts: # app/code/Magento/Inventory/Model/ResourceModel/SourceItem/Collection.php # app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php
|
|
||
| $connection->insertMultiple( | ||
| $connection->getTableName(InstallSchema::TABLE_NAME_SOURCE_ITEM), | ||
| $sourceItemData |
There was a problem hiding this comment.
insertMultiple - should be done by Resource model, not Repository.
The repository should be agnostic to the precise adapter which is used under the hood.
So, switching MySQL -> Postgres SQL -> Mongo DB should not affect Repository code. Just persistent layer should be affected (in our current conditions it's Resource model).
In your implementation Repository works directly with MySQL connection
| /** | ||
| * Set source item status. | ||
| * | ||
| * @param bool $status |
There was a problem hiding this comment.
status is not bool anymore
| * Constants for status value. | ||
| */ | ||
| const IS_IN_STOCK = 0; | ||
| const IS_OUT_OF_STOCK = 1; |
There was a problem hiding this comment.
as it's not bool, we could eliminate IS_ prefix
- product form customization
- backend part
- backend part
- backend part
- backend part
| /** | ||
| * Class SourceItemStatus | ||
| * | ||
| * @api |
There was a problem hiding this comment.
Just interfaces should be marked as api. Not implementations
- backend part
- fix unit tests
- fix static tests
- fix builds
|
About failed tests:
|
maghamed
left a comment
There was a problem hiding this comment.
We agreed that UNIQUE key would be added to SourceItem table (Source_id, SKU)
and that would be added in a separate module.
InventoryCatalog
| /** | ||
| * Class SourceItemStatus | ||
| * | ||
| * @api |
| * Source items status values | ||
| */ | ||
| const SOURCE_ITEM_STATUS_OUT_OF_STOCK = 0; | ||
| const SOURCE_ITEM_STATUS_IN_STOCK = 1; |
There was a problem hiding this comment.
why should we introduce new constants if we already have these constants declared in SourceItemInterface ?
There was a problem hiding this comment.
We agreed that UNIQUE key would be added to SourceItem table (Source_id, SKU)
and that would be added in a separate module.
We have separate task for this
https://github.com/magento-engcom/magento2/issues/42
There was a problem hiding this comment.
why should we introduce new constants if we already have these constants declared in SourceItemInterface ?
There are NOT new constants. Constants have been moved so Source model (like as in another source models)
| use Psr\Log\LoggerInterface; | ||
|
|
||
| /** | ||
| * @api |
There was a problem hiding this comment.
if you add api PHP Doc Block , you must provide a description how this API supposed to be used
| use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
|
|
||
| /** | ||
| * Class SourceItem |
There was a problem hiding this comment.
don't give useless comments
| /** | ||
| * @param Context $context | ||
| * @param MultipleSave $multipleSave | ||
| * @param null $connectionName |
There was a problem hiding this comment.
why do you have null in PHP Doc block ?
| $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); | ||
|
|
||
| $sourceItemMap = []; | ||
| if ($sourceItems) { |
There was a problem hiding this comment.
try to avoid unneeded offsets in code. It's harder to read code with offsets
| private function validateSourceItemData(array $sourceItemData) | ||
| { | ||
| if (!isset($sourceItemData[SourceItemInterface::SOURCE_ID])) { | ||
| throw new InputException(__('Wrong Product to Source relation parameters.')); |
| * @param array $sourceItems | ||
| * @return void | ||
| */ | ||
| private function saveSourceItems(array $sourceItems) |
There was a problem hiding this comment.
why do we need to extract separate method for such simple and easy to read operation ?
| use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
|
|
||
| /** | ||
| * Data provider that provide data about source items |
There was a problem hiding this comment.
please fix this description
| namespace Magento\InventoryApi\Api; | ||
|
|
||
| /** | ||
| * Command for multiple saving of source items |
- fixes after CR
- fixes after CR
- fixes after CR
Add "magento/module-inventory-wishlist" to _metapackage/composer.json
ACP2E-3863: [Bundle 2] Update copyrights for MSI and fix static errors.
Description
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist