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_New extends Mage_Rss_Block_Abstract
00035 {
00036 protected function _construct()
00037 {
00038
00039
00040
00041
00042
00043 }
00044
00045 protected function _toHtml()
00046 {
00047 $storeId = $this->_getStoreId();
00048
00049 $newurl = Mage::getUrl('rss/catalog/new');
00050 $title = Mage::helper('rss')->__('New Products from %s',Mage::app()->getStore()->getGroup()->getName());
00051 $lang = Mage::getStoreConfig('general/locale/code');
00052
00053 $rssObj = Mage::getModel('rss/rss');
00054 $data = array('title' => $title,
00055 'description' => $title,
00056 'link' => $newurl,
00057 'charset' => 'UTF-8',
00058 'language' => $lang
00059 );
00060 $rssObj->_addHeader($data);
00061
00062
00063
00064
00065
00066
00067 $product = Mage::getModel('catalog/product');
00068 $todayDate = $product->getResource()->formatDate(time());
00069
00070 $products = $product->getCollection()
00071 ->setStoreId($storeId)
00072 ->addStoreFilter()
00073 ->addAttributeToFilter('news_from_date', array('date'=>true, 'to'=> $todayDate))
00074 ->addAttributeToFilter(array(array('attribute'=>'news_to_date', 'date'=>true, 'from'=>$todayDate), array('attribute'=>'news_to_date', 'is' => new Zend_Db_Expr('null'))),'','left')
00075 ->addAttributeToSort('news_from_date','desc')
00076 ->addAttributeToSelect(array('name', 'short_description', 'description', 'price', 'thumbnail'), 'inner')
00077 ->addAttributeToSelect(array('special_price', 'special_from_date', 'special_to_date'), 'left')
00078 ;
00079
00080 Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
00081 Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
00082
00083
00084
00085
00086
00087 Mage::getSingleton('core/resource_iterator')
00088 ->walk($products->getSelect(), array(array($this, 'addNewItemXmlCallback')), array('rssObj'=> $rssObj, 'product'=>$product));
00089
00090 return $rssObj->createRssXml();
00091 }
00092
00093 public function addNewItemXmlCallback($args)
00094 {
00095 $product = $args['product'];
00096
00097 $product->setData($args['row']);
00098 $final_price = $product->getFinalPrice();
00099 $description = '<table><tr>'.
00100 '<td><a href="'.$product->getProductUrl().'"><img src="'. $this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75) .'" border="0" align="left" height="75" width="75"></a></td>'.
00101 '<td style="text-decoration:none;">'.$product->getDescription().
00102 '<p> Price:'.Mage::helper('core')->currency($product->getPrice()).
00103 ($product->getPrice() != $final_price ? ' Special Price:'. Mage::helper('core')->currency($final_price) : '').
00104 '</p>'.
00105 '</td>'.
00106 '</tr></table>';
00107 $rssObj = $args['rssObj'];
00108 $data = array(
00109 'title' => $product->getName(),
00110 'link' => $product->getProductUrl(),
00111 'description' => $description,
00112
00113 );
00114 $rssObj->_addEntry($data);
00115 }
00116 }