Skip to content

Commit

Permalink
Only add url to collection if flat table is disabled
Browse files Browse the repository at this point in the history
- If flat is disabled use the collection to get the url, else get it from utilising the `catalog/category` helper method `getCategoryUrl()`
  • Loading branch information
josh-carter committed May 8, 2017
1 parent c9eb855 commit 96c1d4b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,24 @@ public function buildCategoryTreeHtml($parentId, $isChild = false)
{
if ($this->sitemapHelper->getConfig('showcategories')) {
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect(array('url', 'name'))
->addAttributeToSelect(array('name'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('parent_id', array('eq' => $parentId));

if(!$this->isEnabledFlat()) {
$categories->addAttributeToSelect('url');
}

$class = ($isChild) ? "subcategories" : "top-level";

$this->categoryTreeHtml .= '<ul class="' . $class . '">';
foreach ($categories as $category) {
$this->categoryTreeHtml .= '<li><a href="' . $category->getUrl() . '" >' . $category->getName() . "</a>";
if($this->isEnabledFlat()) {
$url = Mage::helper('catalog/category')->getCategoryUrl($category);
}else {
$url = $category->getUrl();
}
$this->categoryTreeHtml .= '<li><a href="' . $url . '" >' . $category->getName() . "</a>";
$children = $category->getChildren();
if ($children) {
$this->categoryTreeHtml .= $this->buildCategoryTreeHtml($category->getId(), true);
Expand Down

0 comments on commit 96c1d4b

Please sign in to comment.