-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Fixed rest API products stockitem /V1/products?searchCriteria #22737 #28435
Conversation
Hi @kirtinariya1. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
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. |
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 looks like the mentioned extension attribute is being loaded only upon the product model load
class AfterProductLoad |
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. |
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 |
@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. |
We have an active support case open for this, so we're monitoring this issue as well.
@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? |
Risk is set to medium since it may affect other areas, ProductRepository is being used widely throughout the platform. |
Hi @kirtinariya1, please sign CLA. Otherwise, we can't proceed with your PR. |
Hi @kirtinariya1, I'm closing this PR now due to inactivity. |
Hi @kirtinariya1, thank you for your contribution! |
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)
Manual testing scenarios (*)
Open the Postman
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
Method: GET
Authorization "Use Admin Token"
Check in response There is a "stock_item": object added in extension_attributes section.
Questions or comments
Contribution checklist (*)