adobe / aem-core-cif-components

A set of configurations and components to get you started with AEM Commerce development
Apache License 2.0
102 stars 80 forks source link

unable to fetch url_key value in categories object in products query which is used in com.adobe.cq.commerce.core.components.models.product #979

Closed AAMANATHULLAH closed 1 year ago

AAMANATHULLAH commented 1 year ago

We have upgraded CIF version from 1.7.0 to 2.12.0 and magento.graphql.version from 6.0.0-magento235 to 9.1.0-magento242ee After upgrade OOTB Products query from com.adobe.cq.commerce.core.components.models.product is including categories{__typename,uid,name,image} object due to which we are unable to get url_key attribute in categories object Attached the products query before and after the upgrade We are using url_key from categories object for custom analytics tracking We are unable to get url_key value in categories object in products query in response which we used to get earlier before upgrade. Please assist here @Buuhuu @herzog31 products_Query_After_upgrade.txt products_Query_Before_upgrade.txt image

buuhuu commented 1 year ago

@LSantha can you have a look

LSantha commented 1 year ago

@AAMANATHULLAH , in a quick test I can see the the url_key you added under categoriescustom is null in the results , while all the other properties have values for the after upgrade query. I think this is a bug in Adobe Commerce (Magento).

AAMANATHULLAH commented 1 year ago

@LSantha We are able to fetch the url_key value from categoriescustom if the categories object is not included in OOTB query which i highlighted in the above screenshot This issue is happening as the categories object is getting included in the OOTB query by CIF product model . I highlighted the same in screenshot attached in issue

buuhuu commented 1 year ago

Fetching the categories of a product has been introduced with 1.8.0:

https://github.com/adobe/aem-core-cif-components/commit/cec4e3f563467514457684304536f6c1d7a11c8e#diff-68c475ec227870432193b3675fe9c5c4fc84315cd7352de0a256db0563fa804a

Currently it is not possible to use the query hook mechanism to extend the a nested field in the query. It seems you added a custom field selection for the categories, which is a reasonable workaround. But @LSantha is right, this is an issue in Adobe Commerce in the way it processes selections that appear multiple times in a query (with or without an alias)

E.g. using https://venia.magento.com/graphql

The query:

{
  products(filter:{ sku: {eq: "VA01"}}) {
    items{
      sku,
      categories{
        name
      },
      categories_custom_: categories {
        url_key
      }
    }
  }
}

does not return the url_key for categories_custom_, but he query

{
  products(filter:{ sku: {eq: "VA01"}}) {
    items{
      sku,
      categories {
        name
        url_key
      },
      categories_custom_: categories {
        url_key
      }
    }
  }
}

does. Actually even

{
  products(filter:{ sku: {eq: "VA01"}}) {
    items{
      sku,
      categories {
        name
      },
      categories {
        url_key
      }
    }
  }
}

would be valid. We should loop in someone from the Magento team here.

AAMANATHULLAH commented 1 year ago

@Buuhuu @LSantha Thanks for your help Adobe Magento team has provided a patch to fix this issue and we are now able to fetch the url_key value in categories object in products query