Skip to content

Commit 93e63a3

Browse files
authored
Merge pull request #17 from ProxiBlue/ProxiBlue-patch-2-cms-page-custom-order
Proxi blue patch 2 cms page custom order
2 parents 3c6d6d7 + 74b0ec8 commit 93e63a3

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
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+
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ Go to `Admin Panel > Stores > Settings > Configuration > Magepow > Categories`
9494

9595
![config-module-img](https://github.com/magepow/magento-2-categories/blob/master/media/magento-2-categories-10.jpg)
9696

97-
The home page also has the same settings as the category page, except that the home page can choose the display categories instead of excluding the display category.
97+
The home page also has the same settings as the category page, except that:
98+
99+
* The home page can choose the display categories instead of excluding the display category.
100+
* The home page can order the categories by 'custom sort', which will display in the order ids appear in the config value.
101+
You can curate this by manually setting the ids in the env.php file to override admin based config.
102+
```
103+
./bin/magento config:set -e magepow_categories/home_page/category_select "64,72,73,1052,68,69,70,1046,65,88,311"
104+
```
98105
* Select the categories displayed on the home page.
99106

100107
![config-module-img](https://github.com/magepow/magento-2-categories/blob/master/media/magento-2-categories-11.jpg)

0 commit comments

Comments
 (0)