From c9eb8550136faeadbfb886328f7cbc1eac33647f Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 8 May 2017 11:51:00 +0100 Subject: [PATCH 1/2] Add new methods to check if category flat is enabled --- .../Creare/CreareSeoSitemap/Block/Sitemap.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php b/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php index a6c6e6b..d914589 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 */ From 96c1d4b2b3d72a70e0e81cba151b0d26b66653da Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 8 May 2017 11:51:55 +0100 Subject: [PATCH 2/2] Only add `url` to collection if flat table is disabled - If flat is disabled use the collection to get the url, else get it from utilising the `catalog/category` helper method `getCategoryUrl()` --- .../Creare/CreareSeoSitemap/Block/Sitemap.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php b/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php index d914589..6281c23 100644 --- a/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php +++ b/app/code/community/Creare/CreareSeoSitemap/Block/Sitemap.php @@ -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 .= '