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.48k stars 9.29k forks source link

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

Open ioweb-gr opened 2 months ago

ioweb-gr commented 2 months ago

Preconditions and environment

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

m2-assistant[bot] commented 2 months ago

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:

m2-assistant[bot] commented 2 months ago

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:

engcom-Hotel commented 2 months ago

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

github-jira-sync-bot commented 2 months ago

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

m2-assistant[bot] commented 2 months ago

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

ioweb-gr commented 2 months ago

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