Skip to content

Commit 4c00c81

Browse files
authored
Update Cmspage.php
1 parent 3c6d6d7 commit 4c00c81

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Block/Cmspage.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,25 @@ public function getCategories()
5858
$categoryIds = $this->getCategorySelect();
5959
if(!$categoryIds) return;
6060

61-
$sortAttribute = $this->getSortAttribute();
61+
$sortAttribute = $this->getSortAttribute();
6262
$categories = $this->categoryFactory->create()->getCollection()
6363
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image', 'description'])
6464
->addIdFilter($categoryIds)
6565
->addIsActiveFilter();
6666

67-
if($sortAttribute == "position") {
68-
$categories->addAttributeToSort('level');
67+
switch ($sortAttribute) {
68+
case 'position':
69+
$categories->addAttributeToSort('level');
70+
break;
71+
case 'custom':
72+
// will sort as per order of Id's set in config value: magepow_categories/home_page/category_select
73+
$categories->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id,' . $categoryIds . ')'));
74+
break;
75+
default:
76+
$categories->addAttributeToSort($sortAttribute);
77+
break;
6978
}
7079

71-
$categories->addAttributeToSort($sortAttribute);
72-
7380
return $categories;
7481
}
75-
}
82+
}

0 commit comments

Comments
 (0)