-
Notifications
You must be signed in to change notification settings - Fork 248
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
Source item management #38
Conversation
source item management
$connection, | ||
$resource | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need to have next methods in this interface and implementation
getExtensionAttributes()/
setExtensionAttributes(\Magento\InventoryApi\Api\Data\SourceItemExtensionInterface $extensionAttributes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i fix this
* @param bool $status | ||
* @return void | ||
*/ | ||
public function setStatus($status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getExtensionAttributes()/
setExtensionAttributes(\Magento\InventoryApi\Api\Data\SourceItemExtensionInterface $extensionAttributes)
/** | ||
* Get source item status. | ||
* | ||
* @return bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type should be void, not int
|
||
use Magento\Framework\Api\ExtensibleDataInterface; | ||
|
||
interface SourceItemInterface extends ExtensibleDataInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this search criteria should not be nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just interfaces should be marked as api. Not implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is source model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
- backend part
- fix unit tests
- fix static tests
- fix builds
About failed tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should we introduce new constants if we already have these constants declared in SourceItemInterface ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
@@ -16,6 +16,9 @@ | |||
use Magento\InventoryApi\Api\Data\SourceInterface; | |||
use Psr\Log\LoggerInterface; | |||
|
|||
/** | |||
* @api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't give useless comments
/** | ||
* @param Context $context | ||
* @param MultipleSave $multipleSave | ||
* @param null $connectionName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you have null in PHP Doc block ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
$sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); | ||
|
||
$sourceItemMap = []; | ||
if ($sourceItems) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameters -> given
* @param array $sourceItems | ||
* @return void | ||
*/ | ||
private function saveSourceItems(array $sourceItems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix this description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
namespace Magento\InventoryApi\Api; | ||
|
||
/** | ||
* Command for multiple saving of source items |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the description
- fixes after CR
- fixes after CR
- fixes after CR
Add "magento/module-inventory-wishlist" to _metapackage/composer.json
Description
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist