diff --git a/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php b/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php index a6c6e6b..6281c23 100644 --- a/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php +++ b/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php @@ -6,6 +6,7 @@ protected $store; protected $sitemapHelper; protected $xmlSitemaps = false; + protected $_flatEnabled = array(); public function __construct(array $args) { @@ -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 */ @@ -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 .= '