magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

"/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section #22737

Closed menacoders closed 3 years ago

menacoders commented 5 years ago

Preconditions

  1. Magento 2.2.7 community Edition.
  2. REST API filtering products using rest/V1/products?searchCriteria

Steps to reproduce

  1. we have disable showing out of stock products from Magento Dashboard (Stores > Configuration > Catalog > Inventory > Display Out of stock products No)
  2. we using this api to filtering product /rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=35&searchCriteria[current_page]=1&searchCriteria[page_size]=40

Expected result

  1. The response contains infromation about stock per each product in the "extension_attributes" section

Actual result

  1. There is no information about stock status per product in "extension_attributes" and no possibility to understand is it available on Storefront
m2-assistant[bot] commented 5 years ago

Hi @MagentoAr. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

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

@MagentoAr do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

m2-assistant[bot] commented 5 years ago

Hi @AlexWorking. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

menacoders commented 5 years ago

Hi @AlexWorking thank you very much for working on this issue. i'll waiting your updates.

menacoders commented 5 years ago

@AlexWorking @vteofilo

any help in this issue would be great.. it's urgent problem in our store .

Thanks & Regards

vteofilo commented 5 years ago

@MagentoAr , please look at my solution:

https://github.com/magento/magento2/issues/15201#issuecomment-417867348

Hope this helps!

vteofilo commented 5 years ago

@vteofilo thank you but i really don't know where to put your code.

Can you find the StockRegistry.php class?

vteofilo commented 5 years ago

@vteofilo thank you but i really don't know where to put your code.

Can you find the StockRegistry.php class?

yes i found it on this path /vendor/magento/module-catalog-inventory/Model/StockRegistry.php

but i don't know wheres to put the code

You must override the syncProductStock method.

menacoders commented 5 years ago

@vteofilo thank you but i really don't know where to put your code.

Can you find the StockRegistry.php class?

yes i found it on this path /vendor/magento/module-catalog-inventory/Model/StockRegistry.php but i don't know wheres to put the code

You must override the syncProductStock method.

i couldn't find any method called syncProductStock in this file /vendor/magento/module-catalog-inventory/Model/StockRegistry.php

menacoders commented 5 years ago

@vteofilo any help would be great

sdzhepa commented 5 years ago

Hello @MagentoAr

Thank you for the report!

We investigated this issue and as results:

  1. Initially "/rest/V1/products?searchCriteria" API endpoint was developed for wider use and it should not returns only In Stock products by design. Even if you set "Stores > Configuration > Catalog > Inventory > Display Out of stock products No" the product will be available by direct URL on Storefront. I suppose it needs for SEO purposes and indexation by other systems. And because of that issue cannot be confirmed and proved for fix with described use case

  2. But the real bug is "/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section.

so, I updated Issue title and description with this information Are you ok with this?

magento-engcom-team commented 5 years ago

:white_check_mark: Confirmed by @sdzhepa Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-99618, MAGETWO-99619 were created

Issue Available: @sdzhepa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] commented 5 years ago

Hi @milindsingh. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

m2-assistant[bot] commented 5 years ago

Hi @mallikaverma. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


dwang12 commented 5 years ago

Hi Guys,

We're also experiencing this in a production setting. Any updates would be greatly appreciated.

Thanks!

farhansaid127 commented 5 years ago

✅ Confirmed by @sdzhepa Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-99618, MAGETWO-99619 were created

Issue Available: @sdzhepa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

But we are still not able to find if product available in stock or not, there is no parameter in search result that shows whether the product available in stock or out of stock

farhansaid127 commented 5 years ago

Hello @MagentoAr

Thank you for the report!

We investigated this issue and as results:

  1. Initially "/rest/V1/products?searchCriteria" API endpoint was developed for wider use and it should not returns only In Stock products by design. Even if you set "Stores > Configuration > Catalog > Inventory > Display Out of stock products No" the product will be available by direct URL on Storefront. I suppose it needs for SEO purposes and indexation by other systems. And because of that issue cannot be confirmed and proved for fix with described use case
  2. But the real bug is "/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section.

so, I updated Issue title and description with this information Are you ok with this?

But we are still not able to find if product available in stock or not, there is no parameter in search result that shows whether the product available in stock or out of stock.

scne commented 3 years ago

any news about this issue?

menacoders commented 3 years ago

any news about this issue?

@scne it's still not fixed in any version i have built a module to solve this issue, i'll share it with you these days.

menacoders commented 3 years ago

Hi @scne i have uploaded the module, get it from here https://github.com/menacoders/Stock-Info-API-searchCriteria

and let me know if you need anything else 👍

scne commented 3 years ago

Hi @menacoders thank you so much for your help! I'm using Magento 2.3.2, is your code compliant?

menacoders commented 3 years ago

Hi @menacoders thank you so much for your help! I'm using Magento 2.3.2, is your code compliant?

yes, i have build it for m2.3.x

titechnologies commented 3 years ago

Hi @scne i have uploaded the module, get it from here https://github.com/menacoders/Stock-Info-API-searchCriteria

and let me know if you need anything else

Thank you. One question, how can we filter out these out-of-stock products from the API result?

menacoders commented 3 years ago

Hi @scne i have uploaded the module, get it from here https://github.com/menacoders/Stock-Info-API-searchCriteria and let me know if you need anything else

Thank you. One question, how can we filter out these out-of-stock products from the API result?

@titechnologies you are welcome.

you mean, you only want to return the in_stock products ? if that what you want.. you could use this api

rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=quantity_and_stock_status&searchCriteria[filter_groups][0][filters][0][value]=2

just add the quantity_and_stock_status filter so it's will return the in_stock products instock value = 2 outofstock value = 1

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!