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:
42:
43: }
44:
45: protected function _toHtml()
46: {
47: $storeId = $this->_getStoreId();
48:
49: $newurl = Mage::getUrl('rss/catalog/new/store_id/' . $storeId);
50: $title = Mage::helper('rss')->__('New Products from %s',Mage::app()->getStore()->getGroup()->getName());
51: $lang = Mage::getStoreConfig('general/locale/code');
52:
53: $rssObj = Mage::getModel('rss/rss');
54: $data = array('title' => $title,
55: 'description' => $title,
56: 'link' => $newurl,
57: 'charset' => 'UTF-8',
58: 'language' => $lang
59: );
60: $rssObj->_addHeader($data);
61: 62: 63: 64: 65:
66:
67: $product = Mage::getModel('catalog/product');
68:
69: $todayStartOfDayDate = Mage::app()->getLocale()->date()
70: ->setTime('00:00:00')
71: ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
72:
73: $todayEndOfDayDate = Mage::app()->getLocale()->date()
74: ->setTime('23:59:59')
75: ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
76:
77: $products = $product->getCollection()
78: ->setStoreId($storeId)
79: ->addStoreFilter()
80: ->addAttributeToFilter('news_from_date', array('or' => array(
81: 0 => array('date' => true, 'to' => $todayEndOfDayDate),
82: 1 => array('is' => new Zend_Db_Expr('null')))
83: ), 'left')
84: ->addAttributeToFilter('news_to_date', array('or' => array(
85: 0 => array('date' => true, 'from' => $todayStartOfDayDate),
86: 1 => array('is' => new Zend_Db_Expr('null')))
87: ), 'left')
88: ->addAttributeToFilter(
89: array(
90: array('attribute' => 'news_from_date', 'is' => new Zend_Db_Expr('not null')),
91: array('attribute' => 'news_to_date', 'is' => new Zend_Db_Expr('not null'))
92: )
93: )
94: ->addAttributeToSort('news_from_date','desc')
95: ->addAttributeToSelect(array('name', 'short_description', 'description', 'thumbnail'), 'inner')
96: ->addAttributeToSelect(
97: array(
98: 'price', 'special_price', 'special_from_date', 'special_to_date',
99: 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp'
100: ),
101: 'left'
102: )
103: ->applyFrontendPriceLimitations()
104: ;
105:
106: $products->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
107:
108: 109: 110: 111:
112:
113: Mage::getSingleton('core/resource_iterator')->walk(
114: $products->getSelect(),
115: array(array($this, 'addNewItemXmlCallback')),
116: array('rssObj'=> $rssObj, 'product'=>$product)
117: );
118:
119: return $rssObj->createRssXml();
120: }
121:
122: 123: 124: 125: 126:
127: public function addNewItemXmlCallback($args)
128: {
129: $product = $args['product'];
130:
131: $product->setAllowedInRss(true);
132: $product->setAllowedPriceInRss(true);
133: Mage::dispatchEvent('rss_catalog_new_xml_callback', $args);
134:
135: if (!$product->getAllowedInRss()) {
136:
137: return;
138: }
139:
140: $allowedPriceInRss = $product->getAllowedPriceInRss();
141:
142:
143: $product->setData($args['row']);
144: $description = '<table><tr>'
145: . '<td><a href="'.$product->getProductUrl().'"><img src="'
146: . $this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75)
147: .'" border="0" align="left" height="75" width="75"></a></td>'.
148: '<td style="text-decoration:none;">'.$product->getDescription();
149:
150: if ($allowedPriceInRss) {
151: $description .= $this->getPriceHtml($product,true);
152: }
153:
154: $description .= '</td>'.
155: '</tr></table>';
156:
157: $rssObj = $args['rssObj'];
158: $data = array(
159: 'title' => $product->getName(),
160: 'link' => $product->getProductUrl(),
161: 'description' => $description,
162: );
163: $rssObj->_addEntry($data);
164: }
165: }
166: