Skip to content

Fixed rest API products stockitem /V1/products?searchCriteria #22737 #28435

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

Closed

Conversation

kirtinariya1
Copy link
Contributor

@kirtinariya1 kirtinariya1 commented May 30, 2020

Description (*)

Magento 2.3 This pull request (PR) will be merge the added stock item extension_attributes in product list rest API /rest/V1/products?searchCriteria

Fixed Issues (if relevant)

  1. Fixes "/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section #22737, : "/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section
  2. Fixes Rest API missing “stock_item” in to the list of the products #24418

Manual testing scenarios (*)

  1. Open the Postman

  2. Add the API URL: {baseurl}/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=category_id& searchCriteria[filterGroups][0][filters][0][value]=3& searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[sortOrders][0][field]=price& searchCriteria[sortOrders][0][direction]=ASC

  3. Method: GET

  4. Authorization "Use Admin Token"

  5. Check in response There is a "stock_item": object added in extension_attributes section.

Questions or comments

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 are green)

@m2-assistant
Copy link

m2-assistant bot commented May 30, 2020

Hi @kirtinariya1. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@rogyar rogyar self-assigned this May 30, 2020
Copy link
Contributor

@rogyar rogyar left a comment

Choose a reason for hiding this comment

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

It looks like the mentioned extension attribute is being loaded only upon the product model load

and for quote items collection load

<observer name="add_stock_items" instance="Magento\CatalogInventory\Observer\AddStockItemsObserver"/>

I'm not sure if the provided solution is the best way since it will work only on the repository level and introduce one more dependency with the CatalogInventory module (we already have it, but nevertheless).

A more "universal" solution would be to create a separate observer in the CatalogInventory module for the product collection load. But this approach might be harmful from the performance perspective. @sidolov we definitely need your advice here.

In the meantime @kirtinariya1 could you cover your solution by API-functional test, please? Even if we change the approach in the implementation the result will be the same and the test will suit the final solution.

Thank you.

@kirtinariya1
Copy link
Contributor Author

It looks like the mentioned extension attribute is being loaded only upon the product model load

and for quote items collection load

<observer name="add_stock_items" instance="Magento\CatalogInventory\Observer\AddStockItemsObserver"/>

I'm not sure if the provided solution is the best way since it will work only on the repository level and introduce one more dependency with the CatalogInventory module (we already have it, but nevertheless).

A more "universal" solution would be to create a separate observer in the CatalogInventory module for the product collection load. But this approach might be harmful from the performance perspective. @sidolov we definitely need your advice here.

In the meantime @kirtinariya1 could you cover your solution by API-functional test, please? Even if we change the approach in the implementation the result will be the same and the test will suit the final solution.

Thank you.

I have test API and it is working fine.

@rogyar
Copy link
Contributor

rogyar commented Jun 3, 2020

Hi @kirtinariya1. I mean, according to the definition of done. All changes should be covered by automated tests. So you need to create a new API-functional test that will perform /V1/products request and check that the stock_item is present in the response (basically, the automated test will emulate actions described in "Steps to reproduce").
Also, you may extend an existing test instead of creating a new one.

@sidolov
Copy link
Contributor

sidolov commented Jun 3, 2020

@rogyar , @kirtinariya1 it's not a good approach to load stock items for products, most scenarios do not require information about stock and moreover it's the responsibility of another module. We need to separate stock management and catalog, right now we have stock extension attribute for product but it's legacy approach and I prefer do not use it anymore.

@kirtinariya1 If you need stock information you should load products with repository and load stock data in the separate request.

@jeffmowens
Copy link

jeffmowens commented Jun 4, 2020

We have an active support case open for this, so we're monitoring this issue as well.

@kirtinariya1 If you need stock information you should load products with repository and load stock data in the separate request.

@sidolov ... the real world issue for us is that we sync product inventories with our internal ERP system on a 15m internal. The REST API response is too slow when designed to iterate as you've suggested ... for performance reasons, we need to pull all relevant product data in a batch. We can appreciate the design approach concern you mentioned... so, with that said, do you recommend a better way to pull all managed_stock = true that included stock data and product attribute information?

@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Sep 14, 2020
@gabrieldagama
Copy link
Contributor

Risk is set to medium since it may affect other areas, ProductRepository is being used widely throughout the platform.

@engcom-Charlie engcom-Charlie self-assigned this Sep 21, 2020
@engcom-Charlie
Copy link
Contributor

Hi @kirtinariya1, please sign CLA. Otherwise, we can't proceed with your PR.
Thank you.

@engcom-Charlie
Copy link
Contributor

Hi @kirtinariya1, I'm closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for your collaboration.

@m2-assistant
Copy link

m2-assistant bot commented Oct 5, 2020

Hi @kirtinariya1, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Award: bug fix Component: Catalog Priority: P3 May be fixed according to the position in the backlog. Progress: pending review Release Line: 2.4 Risk: medium Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
7 participants