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

Source item management #38

Merged
merged 22 commits into from
Jul 13, 2017
Merged

Source item management #38

merged 22 commits into from
Jul 13, 2017

Conversation

larsroettig
Copy link
Member

Description

Fixed Issues (if relevant)

  1. magento/magento2#<issue_number>: Issue title
  2. ...

Manual testing scenarios

  1. ...
  2. ...

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

kieronthomas and others added 4 commits June 26, 2017 17:17
MSI
- UI part of product assignment from source page
- Code Review Changes
- Implement List and Delete Function
- Implement Test for List and Delete Function
$connection,
$resource
);
}
Copy link
Contributor

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);
}
Copy link
Contributor

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)

Copy link
Member Author

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);
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member Author

@larsroettig larsroettig Jul 3, 2017

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);
        }
    }

Copy link
Member Author

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);
Copy link
Contributor

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.

Copy link
Member Author

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?

larsroettig and others added 5 commits July 3, 2017 18:44
- Code Review Changes
- Code review changes
- Add new save methode for better performence
- Add new test case for save methode
- Remove nullable search SearchCriteria and the test case
MSI
- Fixes after CR of Source item management #38
…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
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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

Valeriy Nayda added 6 commits July 4, 2017 17:39
MSI
- Source item management #38
- product form customization
- backend part
- backend part
- backend part
- backend part
/**
* Class SourceItemStatus
*
* @api
Copy link
Contributor

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is source model

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Valeriy Nayda added 4 commits July 10, 2017 12:56
- backend part
- fix unit tests
- fix static tests
- fix builds
@naydav
Copy link

naydav commented Jul 10, 2017

About failed tests:

  1. https://travis-ci.org/magento-engcom/magento2/jobs/251955771
    Will be fixed in https://github.com/magento-engcom/magento2/issues/44

  2. app/code/Magento/Inventory/Observer/ProcessSourceItemsObserver.php:16 The class Magento\Inventory\Observer\ProcessSourceItemsObserver declared as final.
    Will be discussed on internal Magento architecture meeting

Copy link
Contributor

@maghamed maghamed left a 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
Copy link
Contributor

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;
Copy link
Contributor

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 ?

Copy link

@naydav naydav Jul 10, 2017

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

Copy link

@naydav naydav Jul 10, 2017

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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 ?

Copy link

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) {
Copy link
Contributor

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.'));
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix this description

Copy link

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the description

Valeriy Nayda added 3 commits July 10, 2017 18:14
- fixes after CR
- fixes after CR
- fixes after CR
@naydav naydav merged commit 9100fa9 into develop Jul 13, 2017
@vrann vrann added msi and removed msi labels Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants