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

139: Show only active categories #164

Merged

Conversation

nuzil
Copy link
Contributor

@nuzil nuzil commented Aug 31, 2018

Description

We fixed this issue with this PR
https://app.zenhub.com/workspace/o/magento/graphql-ce/issues/139
https://app.zenhub.com/workspace/o/magento/graphql-ce/issues/246

So currently only Active categories will be delivered with request

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Aug 31, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@paliarush paliarush left a comment

Choose a reason for hiding this comment

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

Would be perfect if we can cover this with tests.

@naydav
Copy link
Contributor

naydav commented Sep 13, 2018

Pls check

Magento\GraphQl\Catalog\CategoryTest::testCategoriesTree
Failed asserting that null matches expected 'Ololo'.

/opt/bamboo/builds/MCCE23-AT1226-SOE/build-1/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php:87

@andrewizotov
Copy link
Contributor

andrewizotov commented Sep 20, 2018

Pls check

Magento\GraphQl\Catalog\CategoryTest::testCategoriesTree
Failed asserting that null matches expected 'Ololo'.

/opt/bamboo/builds/MCCE23-AT1226-SOE/build-1/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php:87

Hello Valeriy , I tested default behaviour on develop "2.3-develop" branch without my fix .
And I see some problems around child categories . please have a look .
this is your categories tree .
g1

Query from test
image

and answer
image

So category "Category 1.1.1" is nested in category ""Category 1.2" but this is not true . and "Category 12" doesn't have child nodes in tree, but in answer we have it .
Could you investigate why it happen, seems to be all child categories always nested in last node of tree
Thanks

* @param \Iterator $iterator
* @return array
*/
private function processTree(\Iterator $iterator) : array
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this code not necessary anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

…hilds are always coming to last parent. Rewritte way of tree generation
Copy link
Contributor

@paliarush paliarush left a comment

Choose a reason for hiding this comment

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

This is pretty complex change, please make sure to cover it with GraphQL test.

}

return $tree;
}

/**
* Merge together complex categories tree
Copy link
Contributor

Choose a reason for hiding this comment

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

How about categories tree => category trees ?
Same regarding method name itself.

* @param $index
* @return array
*/
private function generateLevelTree($elements, $index): array
Copy link
Contributor

Choose a reason for hiding this comment

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

Method name is not reflecting its purpose, need to read the docs to understand what it is doing. Please consider improving method name.

@nuzil
Copy link
Contributor Author

nuzil commented Nov 8, 2018

@paliarush Tests are there and aligned, just pushed last update

@magento-engcom-team magento-engcom-team modified the milestones: Release: 2.3.0, Release: 2.3.1 Nov 12, 2018
@naydav naydav removed the requires-tests PRs which require GraphQL tests label Nov 12, 2018
$pathElements = explode("/", $category->getPath());
$this->iteratingCategory = $category;

$currentLevelTree = $this->explodePathToArray($pathElements, self::START_CATEGORY_FETCH_LEVEL);
Copy link
Contributor

Choose a reason for hiding this comment

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

@paliarush @nuzil
This changes will be broke current logic

Query:

{
  category(id: 334) {
   id
    name
  }
}

The result before changes:

{
  "data": {
    "category": {
      "id": 334,
      "name": "Cat-1"
    }
  }
}

The result after changes:

{
  "data": {
    "category": {
      "id": 2,
      "name": null
    }
  }
}

The root category has always been loaded first.

Looks like we need to change

const START_CATEGORY_FETCH_LEVEL = 1;

on

const START_CATEGORY_FETCH_LEVEL = 2;

@nuzil
Copy link
Contributor Author

nuzil commented Nov 20, 2018

Hey @naydav, you was close. reason in different deepness level calculation for each category. I extended code and also added one additional test for this case

@raivisdejus
Copy link

@nuzil From the quick glance this fix is still missing sorting by the position. If you re-arrange the categories the tree in GraphQl will not match without this filter. That is implemented here https://github.com/magento/graphql-ce/pull/257/files#diff-b63924c5648c0a0b6c687d44f7bb7db3R105

@naydav and @paliarush I think my solution for the ExtractDataFromCategoryTree.php is simpler and it also has unit tests to cover the basics of the implementation.

@nuzil
Copy link
Contributor Author

nuzil commented Nov 28, 2018

@magento-engcom-team give me test instance

@naydav naydav removed this from the Release: 2.3.1 milestone Dec 7, 2018
@naydav
Copy link
Contributor

naydav commented Dec 18, 2018

We have static tests fail
1)

Magento\Test\Php\LiveCodeTest::testCodeMess
PHP Code Mess has found error(s):
/var/www/html/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php:24	The class CategoryTree has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
FILE: ...l/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 57 | ERROR | [x] Expected 1 space(s) after closing parenthesis;
    |       |     found 0

@nuzil
Copy link
Contributor Author

nuzil commented Dec 19, 2018

Hi @naydav , I fixed test and removed dependency, let me know if there are some other changes required

@magento-engcom-team magento-engcom-team merged commit 754e391 into magento:2.3-develop Jan 24, 2019
@ghost
Copy link

ghost commented Jan 24, 2019

Hi @nuzil, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

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.

7 participants