00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Rss_Block_Catalog_Salesrule extends Mage_Rss_Block_Abstract
00035 {
00036 protected function _construct()
00037 {
00038
00039
00040
00041 $this->setCacheKey('rss_catalog_salesrule_'.$this->getStoreId().'_'.$this->_getCustomerGroupId());
00042 $this->setCacheLifetime(600);
00043 }
00044
00045
00046 protected function _toHtml()
00047 {
00048
00049 $storeId = $this->_getStoreId();
00050 $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
00051
00052 $custGroup = $this->_getCustomerGroupId();
00053
00054 $newurl = Mage::getUrl('rss/catalog/salesrule');
00055 $title = Mage::helper('rss')->__('%s - Discounts and Coupons',Mage::app()->getStore($storeId)->getName());
00056 $lang = Mage::getStoreConfig('general/locale/code');
00057
00058 $rssObj = Mage::getModel('rss/rss');
00059 $data = array('title' => $title,
00060 'description' => $title,
00061 'link' => $newurl,
00062 'charset' => 'UTF-8',
00063 'language' => $lang
00064 );
00065 $rssObj->_addHeader($data);
00066
00067 $now = date('Y-m-d');
00068 $_saleRule = Mage::getModel('salesrule/rule');
00069 $collection = $_saleRule->getResourceCollection()
00070 ->addFieldToFilter('from_date', array('date'=>true, 'to' => $now))
00071 ->addFieldToFilter('website_ids',array('finset' => $websiteId))
00072 ->addFieldToFilter('customer_group_ids', array('finset' => $custGroup))
00073 ->addFieldToFilter('is_rss',1)
00074 ->addFieldToFilter('is_active',1)
00075 ->setOrder('from_date','desc');
00076 $collection->getSelect()->where('to_date is null or to_date>=?', $now);
00077 $collection->load();
00078
00079 $url = Mage::getUrl('');
00080
00081 foreach ($collection as $sr) {
00082 $description = '<table><tr>'.
00083 '<td style="text-decoration:none;">'.$sr->getDescription().
00084 '<br/>Discount Start Date: '.$this->formatDate($sr->getFromDate(), 'medium').
00085 ( $sr->getToDate() ? ('<br/>Discount End Date: '.$this->formatDate($sr->getToDate(), 'medium')):'').
00086 ($sr->getCouponCode() ? '<br/> Coupon Code: '.$sr->getCouponCode().'' : '').
00087 '</td>'.
00088 '</tr></table>';
00089 $data = array(
00090 'title' => $sr->getName(),
00091 'description' => $description,
00092 'link' => $url
00093 );
00094 $rssObj->_addEntry($data);
00095 }
00096 return $rssObj->createRssXml();
00097 }
00098 }