/** * @param Mage_Catalog_Model_Category $category * @return mixed */ public function getImageUrl($category) { $url = null; if ($image = $category->getThumbnail()) { $url = Mage::getBaseUrl('media') . 'catalog/category/' . $image; } if (!$url) { $url = $category->getImageUrl(); } return $this->_getExportHelper()->parseUrl($url); }
/** * == displayCategoryThumbnail * * returns either the category's thumbnail image if it exists * or default to the placeholder image * * @param Mage_Catalog_Model_Category $category * @param integer|string $width # width of the thumbnail * @param integer|string $height # height of the thumbnail * @return string */ public function displayCategoryThumbnail(Mage_Catalog_Model_Category $category, $width = 168, $height = 168) { /** * check if the category's thumbnail exists in the file structure; * if it doesn't then return a placeholder image */ try { $catThumb = $category->getThumbnail(); $filename = $this->getCategoryBaseDir() . $catThumb; if (!empty($catThumb) && file_exists($filename)) { $imgUrl = $this->getCategoryBaseUrl() . $catThumb; } else { $imgUrl = $this->getDefaultCategoryThumbnail($width, $height); } } catch (Exception $e) { Mage::log($e->getMessage()); $imgUrl = $this->getDefaultCategoryThumbnail($width, $height); } $catName = $this->htmlEscape($category->getName()); return $thumb = "<img src='{$imgUrl}' height='{$height}px' width='{$width}px' alt='{$catName}' />"; }
/** * Based on provided category object returns small category array with necessary data. * * @param Mage_Catalog_Model_Category $c * @return array */ public function categoryToArray($c) { $category = array(); $category['url'] = $c->getUrl(); $category['name'] = Mage::helper('core')->htmlEscape($c->getName()); $category['image'] = $c->getImage(); $category['thumbnail'] = $c->getThumbnail(); $category['description'] = Mage::helper('core')->htmlEscape($c->getDescription()); $category['meta_description'] = Mage::helper('core')->htmlEscape($c->getMetaDescription()); return $category; }