Skip to content

Commit

Permalink
Merge pull request adampmoss#106 from josh-carter/adampmoss#105-sqlst…
Browse files Browse the repository at this point in the history
…ate-fix

adampmoss#105 sqlstate fix
  • Loading branch information
adampmoss authored Jun 28, 2017
2 parents 32e2599 + 96c1d4b commit ef40f38
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
protected $store;
protected $sitemapHelper;
protected $xmlSitemaps = false;
protected $_flatEnabled = array();

public function __construct(array $args)
{
Expand All @@ -20,6 +21,36 @@ public function __construct(array $args)
parent::__construct($args);
}

/**
* Retrieve Catalog Product Flat Helper object
*
* @return Mage_Catalog_Helper_Product_Flat
*/
public function getFlatHelper()
{
return Mage::helper('catalog/category_flat');
}

/**
* Retrieve is flat enabled flag
* Return always false if magento run admin
*
* @return bool
*/
public function isEnabledFlat()
{
// Flat Data can be used only on frontend
if (Mage::app()->getStore()->isAdmin()) {
return false;
}
$storeId = $this->getStoreId();
if (!isset($this->_flatEnabled[$storeId])) {
$flatHelper = $this->getFlatHelper();
$this->_flatEnabled[$storeId] = $flatHelper->isAvailable() && $flatHelper->isBuilt($storeId);
}
return $this->_flatEnabled[$storeId];
}

/**
* @return Creare_CreareSeoSitemap_Helper_Data
*/
Expand Down Expand Up @@ -123,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 ef40f38

Please sign in to comment.