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_Abstract
35: {
36: protected function _construct()
37: {
38: 39: 40:
41: $this->setCacheKey('rss_catalog_salesrule_'.$this->getStoreId().'_'.$this->_getCustomerGroupId());
42: $this->setCacheLifetime(600);
43: }
44:
45: 46: 47: 48: 49:
50: protected function _toHtml()
51: {
52: $storeId = $this->_getStoreId();
53: $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
54: $customerGroup = $this->_getCustomerGroupId();
55: $now = date('Y-m-d');
56: $url = Mage::getUrl('');
57: $newUrl = Mage::getUrl('rss/catalog/salesrule');
58: $lang = Mage::getStoreConfig('general/locale/code');
59: $title = Mage::helper('rss')->__('%s - Discounts and Coupons',Mage::app()->getStore($storeId)->getName());
60:
61:
62: $rssObject = Mage::getModel('rss/rss');
63:
64: $collection = Mage::getModel('salesrule/rule')->getResourceCollection();
65:
66: $data = array(
67: 'title' => $title,
68: 'description' => $title,
69: 'link' => $newUrl,
70: 'charset' => 'UTF-8',
71: 'language' => $lang
72: );
73: $rssObject->_addHeader($data);
74:
75: $collection->addWebsiteGroupDateFilter($websiteId, $customerGroup, $now)
76: ->addFieldToFilter('is_rss', 1)
77: ->setOrder('from_date','desc');
78: $collection->load();
79:
80: foreach ($collection as $sr) {
81: $description = '<table><tr>'.
82: '<td style="text-decoration:none;">'.$sr->getDescription().
83: '<br/>Discount Start Date: '.$this->formatDate($sr->getFromDate(), 'medium').
84: ( $sr->getToDate() ? ('<br/>Discount End Date: '.$this->formatDate($sr->getToDate(), 'medium')):'').
85: ($sr->getCouponCode() ? '<br/> Coupon Code: '.$sr->getCouponCode().'' : '').
86: '</td>'.
87: '</tr></table>';
88: $data = array(
89: 'title' => $sr->getName(),
90: 'description' => $description,
91: 'link' => $url
92: );
93: $rssObject->_addEntry($data);
94: }
95:
96: return $rssObject->createRssXml();
97: }
98: }
99: