Closed
Description
Magento does not return all the required information while using fragments on products query.
Preconditions (*)
Magento 2.3.x and Magento 2.4.x
Steps to reproduce (*)
Run a GraphQL query with fragments like the following one:
query GetProducts {
products(filter:{category_id:{eq:"3"}}) {
items {
sku
...BasicProductInformation
}
}
}
fragment BasicProductInformation on ProductInterface {
sku
name
canonical_url
small_image {
label
url
}
price {
regularPrice {
amount {
value
currency
}
}
}
}
Expected result (*)
The expected result is to have the right image url and product price as well as other fields
Actual result (*)
The actual result always presents placeholders for images and zero price:
{
"data": {
"products": {
"items": [
...
{
"sku": "product_dynamic_111",
"name": null,
"canonical_url": "http://magento.local/simple-product-111.html",
"small_image": {
"label": "Simple Product 111",
"url": "http://magento.local/static/version1577790407/graphql/_view/en_US/Magento_Catalog/images/product/placeholder/small_image.jpg"
},
"thumbnail": {
"label": "Simple Product 111",
"url": "http://magento.local/static/version1577790407/graphql/_view/en_US/Magento_Catalog/images/product/placeholder/thumbnail.jpg"
},
"special_price": null,
"price": {
"maximalPrice": {
"amount": {
"value": 0,
"currency": "EUR"
}
},
"minimalPrice": {
"amount": {
"value": 0,
"currency": "EUR"
}
},
"regularPrice": {
"amount": {
"value": 0,
"currency": "EUR"
}
}
}
}
...
The problem seems to be located in \Magento\CatalogGraphQl\Model\Resolver\Products\Query\FieldSelection::getProductsFieldSelection
for Magento 2.4 and \Magento\CatalogGraphQl\Model\Resolver\Product\ProductFieldsSelector::getProductFieldsFromInfo
for Magento 2.3 .
Both methods do not analyze the defined fragments for the fields list and thus skipping their selection.