Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Added a separate resolver for returning category products count #243

Merged
merged 4 commits into from
Nov 20, 2018

Conversation

rogyar
Copy link
Contributor

@rogyar rogyar commented Nov 8, 2018

Description (*)

The product_count field of the category query now returns a value from the corresponding field of catalog_category_entity. Using this approach brings additional issues since the value in the database sometimes does not reflect the real products count. Moreover, if we request products of this category, the GraphQL query returns only products that are saleable (visible and in stock). So product_count value will show the different result if some products of the category are out of stock or not visible.

Fixed Issues (if relevant)

  1. Incorrect returned values of product_count #214 : Incorrect returned values of product_count
  2. Configurable Products counted but not retrieved in GraphQL (works with REST endpoint) #238 : Configurable Products counted but not retrieved in GraphQL (works with REST endpoint)

Manual testing scenarios (*)

  1. Add some products to a category and make some of them out of stock or not visible individually
  2. Use a similar query to retrieve the category and products:
{
  category(id: 1158) {
    product_count
    products {
      items {
        name
      }
      total_count
    }
  }
}
  1. The value in product_count field should corresponds to the total number of fetched products
  2. The value in total_count field should equal the value in products_count

@magento-engcom-team magento-engcom-team deleted the category-products-count-fix branch November 9, 2018 11:29
@VladimirZaets VladimirZaets restored the category-products-count-fix branch November 9, 2018 12:54
@VladimirZaets VladimirZaets reopened this Nov 9, 2018
/** @var Category $category */
$category = $value['model'];
$productsCollection = $category->getProductCollection();
$productsCollection->setVisibility($this->catalogProductVisibility->getVisibleInSiteIds());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should have some test cases for tricky scenarios, like:

  • show products out of stock
  • configurables with out of stock children
  • products available in one store, but not available in the other

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corresponding ticket has been created
#255

@magento-engcom-team magento-engcom-team merged commit 3694c65 into 2.3-develop Nov 20, 2018
@naydav naydav removed this from the Release: 2.3.1 milestone Dec 7, 2018
@naydav naydav deleted the category-products-count-fix branch April 12, 2019 19:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants