Skip to content

Commit

Permalink
Merge forwardport of #11342 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11342.patch (created by @denisristic) based on commit(s):
  1. 6dfb610
  2. f77dadb
  3. fc47234
  4. 9d593a4
  5. 79693c8

Fixed GitHub Issues in 2.3-develop branch:
  - #11310: Method "getChildren" sort ordering (reported by @EliasKotlyar)
  • Loading branch information
magento-engcom-team authored Jan 23, 2018
2 parents a173e1c + 2e83a36 commit 41d0075
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,14 @@ public function getAllChildren($asArray = false)
/**
* Retrieve children ids comma separated
*
* @param boolean $recursive
* @param boolean $isActive
* @param boolean $sortByPosition
* @return string
*/
public function getChildren()
public function getChildren($recursive = false, $isActive = true, $sortByPosition = false)
{
return implode(',', $this->getResource()->getChildren($this, false));
return implode(',', $this->getResource()->getChildren($this, $recursive, $isActive, $sortByPosition));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,10 @@ public function isInRootCategoryList($category)
* @param \Magento\Catalog\Model\Category $category
* @param bool $recursive
* @param bool $isActive
* @param bool $sortByPosition
* @return array
*/
public function getChildren($category, $recursive = true, $isActive = true)
public function getChildren($category, $recursive = true, $isActive = true, $sortByPosition = false)
{
$select = $this->getConnection()->select()->from(
$this->getMainStoreTable($category->getStoreId()),
Expand All @@ -619,6 +620,9 @@ public function getChildren($category, $recursive = true, $isActive = true)
if ($isActive) {
$select->where('is_active = ?', '1');
}
if ($sortByPosition) {
$select->order('position ASC');
}
$_categories = $this->getConnection()->fetchAll($select);
$categoriesIds = [];
foreach ($_categories as $_category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public function testGetChildren()
$this->assertEquals(array_diff([4, 13], explode(',', $this->_model->getChildren())), []);
}

public function testGetChildrenSorted()
{
$this->_model->load(2);
$unsorted = explode(',', $this->_model->getChildren());
sort($unsorted);
$this->assertEquals(array_diff($unsorted, explode(',', $this->_model->getChildren(true, true, true))), []);
}

public function testGetPathInStore()
{
$this->_model->load(5);
Expand Down

0 comments on commit 41d0075

Please sign in to comment.