1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_XmlConnect_Block_Home extends Mage_XmlConnect_Block_Catalog
35: {
36: 37: 38:
39: const HOME_PAGE_CATEGORIES_COUNT = 6;
40:
41: 42: 43: 44: 45:
46: protected function _toHtml()
47: {
48:
49: $homeXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<home></home>');
50:
51: $categoryCollection = array();
52: $helper = Mage::helper('catalog/category');
53: $categoryCount = 0;
54: foreach ($helper->getStoreCategories() as $child) {
55: if ($child->getIsActive()) {
56: $categoryCollection[] = $child;
57: $categoryCount++;
58: }
59: if ($categoryCount == self::HOME_PAGE_CATEGORIES_COUNT) {
60: break;
61: }
62: }
63:
64: if (sizeof($categoryCollection)) {
65: $itemsXmlObj = $homeXmlObj->addChild('categories');
66: }
67:
68: foreach ($categoryCollection as $item) {
69:
70: $item = Mage::getModel('catalog/category')->load($item->getId());
71: $itemXmlObj = $itemsXmlObj->addChild('item');
72: $itemXmlObj->addChild('label', $homeXmlObj->escapeXml($item->getName()));
73: $itemXmlObj->addChild('entity_id', $item->getId());
74: $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products');
75: $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail')
76: ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category'));
77:
78: $iconXml = $itemXmlObj->addChild('icon', $icon);
79: $file = Mage::helper('xmlconnect')->urlToPath($icon);
80: $iconXml->addAttribute('modification_time', filemtime($file));
81: }
82: $homeXmlObj->addChild('home_banner', '/current/media/catalog/category/banner_home.png');
83:
84: return $homeXmlObj->asNiceXml();
85: }
86: }
87: