Skip to content

Commit

Permalink
Merge pull request #17 from ProxiBlue/ProxiBlue-patch-2-cms-page-cust…
Browse files Browse the repository at this point in the history
…om-order

Proxi blue patch 2 cms page custom order
  • Loading branch information
magiccart authored Jan 23, 2024
2 parents 3c6d6d7 + 74b0ec8 commit 93e63a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 13 additions & 6 deletions Block/Cmspage.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,25 @@ public function getCategories()
$categoryIds = $this->getCategorySelect();
if(!$categoryIds) return;

$sortAttribute = $this->getSortAttribute();
$sortAttribute = $this->getSortAttribute();
$categories = $this->categoryFactory->create()->getCollection()
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image', 'description'])
->addIdFilter($categoryIds)
->addIsActiveFilter();

if($sortAttribute == "position") {
$categories->addAttributeToSort('level');
switch ($sortAttribute) {
case 'position':
$categories->addAttributeToSort('level');
break;
case 'custom':
// will sort as per order of Id's set in config value: magepow_categories/home_page/category_select
$categories->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id,' . $categoryIds . ')'));
break;
default:
$categories->addAttributeToSort($sortAttribute);
break;
}

$categories->addAttributeToSort($sortAttribute);

return $categories;
}
}
}
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ Go to `Admin Panel > Stores > Settings > Configuration > Magepow > Categories`

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

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.
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.
* The home page can order the categories by 'custom sort', which will display in the order ids appear in the config value.
You can curate this by manually setting the ids in the env.php file to override admin based config.
```
./bin/magento config:set -e magepow_categories/home_page/category_select "64,72,73,1052,68,69,70,1046,65,88,311"
```
* Select the categories displayed on the home page.

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

0 comments on commit 93e63a3

Please sign in to comment.