Example #1
0
 /**
  * Adds url_path property for non-root category - to ensure that url path is not empty.
  *
  * Sometimes attribute 'url_path' can be empty, because url_path hasn't been generated yet,
  * in this case category is loaded with empty url_path and we should generate it manually.
  *
  * @param Varien_Object $category
  * @return void
  */
 protected function _addCategoryUrlPath($category)
 {
     if (!$category instanceof Varien_Object || $category->getUrlPath()) {
         return;
     }
     // This routine is not intended to be used with root categories,
     // but handle 'em gracefully - ensure them to have empty path.
     if ($category->getLevel() <= 1) {
         $category->setUrlPath('');
         return;
     }
     if (self::$_categoryForUrlPath === null) {
         self::$_categoryForUrlPath = Mage::getModel('catalog/category');
     }
     // Generate url_path
     $urlPath = self::$_categoryForUrlPath->setData($category->getData())->getUrlPath();
     $category->setUrlPath($urlPath);
 }