Skip to content

Commit

Permalink
[bug-OpenMage#351] Position attribute of child categories is ignored
Browse files Browse the repository at this point in the history
Categories returned by getChildren() should be sorted by position.

refs: OpenMage#350
  • Loading branch information
EliasKotlyar authored and edannenberg committed Oct 25, 2019
1 parent ee281be commit aeaf227
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/code/core/Mage/Catalog/Model/Resource/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ public function getChildren($category, $recursive = true)
'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id',
array()
)
->where($checkSql . ' = :scope');
->where($checkSql . ' = :scope')
->order("m.position ASC");

return $adapter->fetchCol($select, $bind);
}
Expand Down
7 changes: 5 additions & 2 deletions app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php
Original file line number Diff line number Diff line change
Expand Up @@ -1311,15 +1311,18 @@ public function isInRootCategoryList($category)
*/
public function getChildren($category, $recursive = true, $isActive = true)
{
$maintable = $this->getMainStoreTable($category->getStoreId());
$select = $this->_getReadAdapter()->select()
->from($this->getMainStoreTable($category->getStoreId()), 'entity_id')
->where('path LIKE ?', "{$category->getPath()}/%");
->from($maintable, 'entity_id')
->where('path LIKE ?', "{$category->getPath()}/%")
->order($maintable.".position ASC");
if (!$recursive) {
$select->where('level <= ?', $category->getLevel() + 1);
}
if ($isActive) {
$select->where('is_active = ?', '1');
}

$_categories = $this->_getReadAdapter()->fetchAll($select);
$categoriesIds = array();
foreach ($_categories as $_category) {
Expand Down

0 comments on commit aeaf227

Please sign in to comment.