Skip to content

Commit ef40f38

Browse files
authored
Merge pull request #106 from josh-carter/#105-sqlstate-fix
#105 sqlstate fix
2 parents 32e2599 + 96c1d4b commit ef40f38

File tree

1 file changed

+42
-2
lines changed
  • app/code/community/Creare/CreareSeoSitemap/Block

1 file changed

+42
-2
lines changed

app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php

+42-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
protected $store;
77
protected $sitemapHelper;
88
protected $xmlSitemaps = false;
9+
protected $_flatEnabled = array();
910

1011
public function __construct(array $args)
1112
{
@@ -20,6 +21,36 @@ public function __construct(array $args)
2021
parent::__construct($args);
2122
}
2223

24+
/**
25+
* Retrieve Catalog Product Flat Helper object
26+
*
27+
* @return Mage_Catalog_Helper_Product_Flat
28+
*/
29+
public function getFlatHelper()
30+
{
31+
return Mage::helper('catalog/category_flat');
32+
}
33+
34+
/**
35+
* Retrieve is flat enabled flag
36+
* Return always false if magento run admin
37+
*
38+
* @return bool
39+
*/
40+
public function isEnabledFlat()
41+
{
42+
// Flat Data can be used only on frontend
43+
if (Mage::app()->getStore()->isAdmin()) {
44+
return false;
45+
}
46+
$storeId = $this->getStoreId();
47+
if (!isset($this->_flatEnabled[$storeId])) {
48+
$flatHelper = $this->getFlatHelper();
49+
$this->_flatEnabled[$storeId] = $flatHelper->isAvailable() && $flatHelper->isBuilt($storeId);
50+
}
51+
return $this->_flatEnabled[$storeId];
52+
}
53+
2354
/**
2455
* @return Creare_CreareSeoSitemap_Helper_Data
2556
*/
@@ -123,15 +154,24 @@ public function buildCategoryTreeHtml($parentId, $isChild = false)
123154
{
124155
if ($this->sitemapHelper->getConfig('showcategories')) {
125156
$categories = Mage::getModel('catalog/category')->getCollection()
126-
->addAttributeToSelect(array('url', 'name'))
157+
->addAttributeToSelect(array('name'))
127158
->addAttributeToFilter('is_active', 1)
128159
->addAttributeToFilter('parent_id', array('eq' => $parentId));
129160

161+
if(!$this->isEnabledFlat()) {
162+
$categories->addAttributeToSelect('url');
163+
}
164+
130165
$class = ($isChild) ? "subcategories" : "top-level";
131166

132167
$this->categoryTreeHtml .= '<ul class="' . $class . '">';
133168
foreach ($categories as $category) {
134-
$this->categoryTreeHtml .= '<li><a href="' . $category->getUrl() . '" >' . $category->getName() . "</a>";
169+
if($this->isEnabledFlat()) {
170+
$url = Mage::helper('catalog/category')->getCategoryUrl($category);
171+
}else {
172+
$url = $category->getUrl();
173+
}
174+
$this->categoryTreeHtml .= '<li><a href="' . $url . '" >' . $category->getName() . "</a>";
135175
$children = $category->getChildren();
136176
if ($children) {
137177
$this->categoryTreeHtml .= $this->buildCategoryTreeHtml($category->getId(), true);

0 commit comments

Comments
 (0)