Skip to content

Commit df33eb0

Browse files
committed
Update Sort #8
1 parent 4440beb commit df33eb0

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

Block/Categories.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,24 @@ public function getCurrentCategory()
128128

129129
public function getCategories()
130130
{
131-
132131
$category = $this->getCurrentCategory();
133132
if(!$category) return;
134133

135134
$categoryId = $category->getId();
136135

137136
if ($this->isExcluded($categoryId)) return;
138137

139-
$sortAttribute = $this->getSortAttribute();
140-
$model = $this->categoryFactory->create();
141-
$categories = $model->getCollection()
142-
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image','description'])
143-
// ->addAttributeToFilter('include_in_menu', 1)
144-
->addAttributeToFilter('parent_id', $categoryId)
145-
->addAttributeToSort($sortAttribute)
146-
->addIsActiveFilter();
138+
$sortAttribute = $this->getSortAttribute();
139+
$categories = $this->categoryFactory->create()->getCollection()
140+
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image','description'])
141+
->addAttributeToFilter('parent_id', $categoryId)
142+
->addIsActiveFilter();
143+
144+
if($sortAttribute == "position") {
145+
$categories->addAttributeToSort('level');
146+
}
147+
148+
$categories->addAttributeToSort($sortAttribute);
147149

148150
return $categories;
149151
}

Block/Cmspage.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class Cmspage extends Categories
1515
{
16+
17+
const DEFAULT_CACHE_TAG = 'MAGEPOW_CATEGORIES_CMS';
18+
1619
const XML_PATH = 'home_page';
1720

1821
public function getLayout()
@@ -54,13 +57,18 @@ public function getCategories()
5457
{
5558
$categoryIds = $this->getCategorySelect();
5659
if(!$categoryIds) return;
57-
$sortAttribute = $this->getSortAttribute();
58-
$model = $this->categoryFactory->create();
59-
$categories = $model->getCollection()
60-
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image', 'description'])
61-
->addAttributeToSort($sortAttribute)
62-
->addIdFilter($categoryIds)
63-
->addIsActiveFilter();
60+
61+
$sortAttribute = $this->getSortAttribute();
62+
$categories = $this->categoryFactory->create()->getCollection()
63+
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image', 'description'])
64+
->addIdFilter($categoryIds)
65+
->addIsActiveFilter();
66+
67+
if($sortAttribute == "position") {
68+
$categories->addAttributeToSort('level');
69+
}
70+
71+
$categories->addAttributeToSort($sortAttribute);
6472

6573
return $categories;
6674
}

0 commit comments

Comments
 (0)