magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Cannot display out of stock products in graphql when a pwa is accessed by direct URL

Open ioweb-gr opened this issue 1 year ago • 6 comments

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.

  1. Magento needs to be set up to "Do not display out of stock products" in the catalog storefront.
  2. 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”.

ioweb-gr avatar Jun 26 '24 07:06 ioweb-gr

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:


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.

m2-assistant[bot] avatar Jun 26 '24 07:06 m2-assistant[bot]

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: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Jul 01 '24 06:07 m2-assistant[bot]

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

engcom-Hotel avatar Jul 01 '24 07:07 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12315 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Jul 01 '24 08:07 github-jira-sync-bot

: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.

m2-assistant[bot] avatar Jul 01 '24 08:07 m2-assistant[bot]

@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?

ioweb-gr avatar Jul 01 '24 08:07 ioweb-gr

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?

sawwd avatar Sep 19 '24 08:09 sawwd

@magento I am working on this

Rus0 avatar Sep 23 '24 04:09 Rus0

Any update on this ticket?

tuyennn avatar Feb 26 '25 05:02 tuyennn