Cannot display out of stock products in graphql when a pwa is accessed by direct URL
Preconditions and environment
- 2.3.x, 2.4.x
- Any PWA that targets the magento instance using graphql
Steps to reproduce
The problem that we're trying to solve is that we can't get the original behavior of magento with out of stock products.
- Magento needs to be set up to "Do not display out of stock products" in the catalog storefront.
- We need at least one enabled but out of stock product
The existing behavior of magento is that this product won't be visible in collections, but it will be visible on the product page if you access it by a direct URL.
On the PWA using graphql we can only use the products query in conjunction with the urlResolver.
When a user access the direct URL, we use urlResolver to fetch the product ID successfully e.g.
{
"data": {
"urlResolver": {
"canonical_url": "catalog/product/view/id/13869",
"relative_url": "catalog/product/view/id/13869",
"id": 13869,
"type": "PRODUCT"
}
}
}
When we try to fetch the product from the products query with the id it's not fetching it because in the underlying code, a collection is loaded which automatically is flagged to remove out of stock products.
Thus the product cannot be displayed resulting in 404.
This problem is very important for SEO
We need a way to replicate the original behavior of magento to fetch the product data by it's ID via graphQL and then display it as out of stock.
Expected result
The product is fetched by the graphql query by it's ID
Actual result
The product is filtered out because it's out of stock.
Additional information
Keep in mind, we don't want to show all out of stock products everywhere, we just need to retain the functionality of showing the product when it's hit by an indexed direct URL in Google.
IF there's any workaround, could you inform us what it is or what we're doing wrong?
I don't see a path to replicating this functionality currently.
Release note
No response
Triage and priority
- [X] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @ioweb-gr. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
-
@magento give me 2.4-develop instance- upcoming 2.4.x release - For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this - To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Hotel. 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:
- [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
- [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
- [ ] 3. Add
Area: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! - [ ] 5. Add label
Issue: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @ioweb-gr,
Thanks for the report and collaboration!
We have checked this scenario and found that this is a valid issue, the products query cannot fetch out-of-stock products due to the collection's filtering logic. This behavior differs from the traditional Magento frontend behavior where the product page for an out-of-stock product can still be accessed via a direct URL.
This limitation affects SEO because indexed direct URLs to out-of-stock products result in a 404 error, which is detrimental to SEO.
Hence confirming the issue.
Thanks
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12315 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@engcom-Hotel Hi, and thanks for confirming the issue. Do you think you could reach with the team and see what would be acceptable as a solution? Like a high level example of how it would work?
Also, in the GraphQL products query there should be displayed all products like on Admin -> Catalog. I dont get why the out of stock and disabled products are filtered out. Is there any way to just make this optional atleast?
@magento I am working on this
Any update on this ticket?