Skip to content

Commit

Permalink
Update Sort #8
Browse files Browse the repository at this point in the history
  • Loading branch information
magiccart committed May 11, 2021
1 parent 4440beb commit df33eb0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
20 changes: 11 additions & 9 deletions Block/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,24 @@ public function getCurrentCategory()

public function getCategories()
{

$category = $this->getCurrentCategory();
if(!$category) return;

$categoryId = $category->getId();

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

$sortAttribute = $this->getSortAttribute();
$model = $this->categoryFactory->create();
$categories = $model->getCollection()
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image','description'])
// ->addAttributeToFilter('include_in_menu', 1)
->addAttributeToFilter('parent_id', $categoryId)
->addAttributeToSort($sortAttribute)
->addIsActiveFilter();
$sortAttribute = $this->getSortAttribute();
$categories = $this->categoryFactory->create()->getCollection()
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image','description'])
->addAttributeToFilter('parent_id', $categoryId)
->addIsActiveFilter();

if($sortAttribute == "position") {
$categories->addAttributeToSort('level');
}

$categories->addAttributeToSort($sortAttribute);

return $categories;
}
Expand Down
22 changes: 15 additions & 7 deletions Block/Cmspage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

class Cmspage extends Categories
{

const DEFAULT_CACHE_TAG = 'MAGEPOW_CATEGORIES_CMS';

const XML_PATH = 'home_page';

public function getLayout()
Expand Down Expand Up @@ -54,13 +57,18 @@ public function getCategories()
{
$categoryIds = $this->getCategorySelect();
if(!$categoryIds) return;
$sortAttribute = $this->getSortAttribute();
$model = $this->categoryFactory->create();
$categories = $model->getCollection()
->addAttributeToSelect(['name', 'url_key', 'url_path', 'image', 'description'])
->addAttributeToSort($sortAttribute)
->addIdFilter($categoryIds)
->addIsActiveFilter();

$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');
}

$categories->addAttributeToSort($sortAttribute);

return $categories;
}
Expand Down

0 comments on commit df33eb0

Please sign in to comment.