Skip to content

Instantly share code, notes, and snippets.

@herveguetin
Created November 24, 2014 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herveguetin/66d5663fd911f1f6889e to your computer and use it in GitHub Desktop.
Save herveguetin/66d5663fd911f1f6889e to your computer and use it in GitHub Desktop.
When using Magento EE, and especially when flat category is active, requesting the "url_key" attribute for a category fails because it is not populated in catalog_category_flat_store_*. This method fixes that.
<?php
/**
* Get category URL key for Enterprise
*
* @param Mage_Catalog_Model_Category $category
* @return string
*/
public function getEnterpriseUrlKey(Mage_Catalog_Model_Category $category)
{
$resource = Mage::getSingleton('core/resource');
$conn = $resource->getConnection('core_read');
$tableName = $resource->getTableName(array('catalog/category', 'url_key'));
$select = $conn->select()
->from(
array('url_key_table' => $tableName),
array('url_key' => 'url_key_table.value', 'store_id' => 'MAX(url_key_table.store_id)')
)
->where('url_key_table.entity_id = ?', $category->getId())
->where('url_key_table.store_id IN(?)', array(Mage_Core_Model_App::ADMIN_STORE_ID, $category->getStoreId()))
;
$row = $conn->fetchRow($select);
return $row['url_key'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment