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 extends Mage_Rss_Block_Catalog_Abstract
35: {
36: protected function _construct()
37: {
38: 39: 40:
41: $this->setCacheKey('rss_catalog_category_'
42: . $this->getRequest()->getParam('cid') . '_'
43: . $this->getRequest()->getParam('store_id') . '_'
44: . Mage::getModel('customer/session')->getId()
45: );
46: $this->setCacheLifetime(600);
47: }
48:
49: protected function _toHtml()
50: {
51: $categoryId = $this->getRequest()->getParam('cid');
52: $storeId = $this->_getStoreId();
53: $rssObj = Mage::getModel('rss/rss');
54: if ($categoryId) {
55: $category = Mage::getModel('catalog/category')->load($categoryId);
56: if ($category && $category->getId()) {
57: $layer = Mage::getSingleton('catalog/layer')->setStore($storeId);
58:
59: $category->setIsAnchor(true);
60: $newurl = $category->getUrl();
61: $title = $category->getName();
62: $data = array('title' => $title,
63: 'description' => $title,
64: 'link' => $newurl,
65: 'charset' => 'UTF-8',
66: );
67:
68: $rssObj->_addHeader($data);
69:
70: $_collection = $category->getCollection();
71: $_collection->addAttributeToSelect('url_key')
72: ->addAttributeToSelect('name')
73: ->addAttributeToSelect('is_anchor')
74: ->addAttributeToFilter('is_active',1)
75: ->addIdFilter($category->getChildren())
76: ->load()
77: ;
78: $productCollection = Mage::getModel('catalog/product')->getCollection();
79:
80: $currentCategory = $layer->setCurrentCategory($category);
81: $layer->prepareProductCollection($productCollection);
82: $productCollection->addCountToCategories($_collection);
83:
84: $category->getProductCollection()->setStoreId($storeId);
85: 86: 87:
88: $_productCollection = $currentCategory
89: ->getProductCollection()
90: ->addAttributeToSort('updated_at','desc')
91: ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
92: ->setCurPage(1)
93: ->setPageSize(50)
94: ;
95:
96: if ($_productCollection->getSize()>0) {
97: $args = array('rssObj' => $rssObj);
98: foreach ($_productCollection as $_product) {
99: $args['product'] = $_product;
100: $this->addNewItemXmlCallback($args);
101: }
102: }
103: }
104: }
105: return $rssObj->createRssXml();
106: }
107:
108: 109: 110: 111: 112:
113: public function addNewItemXmlCallback($args)
114: {
115: $product = $args['product'];
116: $product->setAllowedInRss(true);
117: $product->setAllowedPriceInRss(true);
118:
119: Mage::dispatchEvent('rss_catalog_category_xml_callback', $args);
120:
121: if (!$product->getAllowedInRss()) {
122: return;
123: }
124:
125: $description = '<table><tr>'
126: . '<td><a href="'.$product->getProductUrl().'"><img src="'
127: . $this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75)
128: . '" border="0" align="left" height="75" width="75"></a></td>'
129: . '<td style="text-decoration:none;">' . $product->getDescription();
130:
131: if ($product->getAllowedPriceInRss()) {
132: $description.= $this->getPriceHtml($product,true);
133: }
134:
135: $description .= '</td></tr></table>';
136: $rssObj = $args['rssObj'];
137: $data = array(
138: 'title' => $product->getName(),
139: 'link' => $product->getProductUrl(),
140: 'description' => $description,
141: );
142:
143: $rssObj->_addEntry($data);
144: }
145: }
146: