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_List extends Mage_Core_Block_Template
00035 {
00036 const XML_PATH_RSS_METHODS = 'rss';
00037
00038 protected $_rssFeeds = array();
00039
00040
00041
00042
00043
00044
00045
00046 public function getRssFeeds()
00047 {
00048 return empty($this->_rssFeeds) ? false : $this->_rssFeeds;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058 public function addRssFeed($url, $label, $param = array(), $customerGroup=false)
00059 {
00060 $param = array_merge($param, array('store_id' => $this->getCurrentStoreId()));
00061 if ($customerGroup) {
00062 $param = array_merge($param, array('cid' => $this->getCurrentCustomerGroupId()));
00063 }
00064
00065 $this->_rssFeeds[] = new Varien_Object(
00066 array(
00067 'url' => Mage::getUrl($url, $param),
00068 'label' => $label
00069 )
00070 );
00071 return $this;
00072 }
00073
00074 public function resetRssFeed()
00075 {
00076 $this->_rssFeeds=array();
00077 }
00078
00079 public function getCurrentStoreId()
00080 {
00081 return Mage::app()->getStore()->getId();
00082 }
00083
00084 public function getCurrentCustomerGroupId()
00085 {
00086 return Mage::getSingleton('customer/session')->getCustomerGroupId();
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096 public function getRssCatalogFeeds()
00097 {
00098 $this->resetRssFeed();
00099 $this->CategoriesRssFeed();
00100 return $this->getRssFeeds();
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 }
00115
00116 public function getRssMiscFeeds()
00117 {
00118 $this->resetRssFeed();
00119 $this->NewProductRssFeed();
00120 $this->SpecialProductRssFeed();
00121 $this->SalesRuleProductRssFeed();
00122 return $this->getRssFeeds();
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 public function NewProductRssFeed()
00140 {
00141 $path = self::XML_PATH_RSS_METHODS.'/catalog/new';
00142 if((bool)Mage::getStoreConfig($path)){
00143 $this->addRssFeed($path, $this->__('New Products'));
00144 }
00145 }
00146
00147 public function SpecialProductRssFeed()
00148 {
00149 $path = self::XML_PATH_RSS_METHODS.'/catalog/special';
00150 if((bool)Mage::getStoreConfig($path)){
00151 $this->addRssFeed($path, $this->__('Special/Discount Products'),array(),true);
00152 }
00153 }
00154
00155 public function SalesRuleProductRssFeed()
00156 {
00157 $path = self::XML_PATH_RSS_METHODS.'/catalog/salesrule';
00158 if((bool)Mage::getStoreConfig($path)){
00159 $this->addRssFeed($path, $this->__('Coupons/Discounts'),array(),true);
00160 }
00161 }
00162
00163 public function CategoriesRssFeed()
00164 {
00165 $path = self::XML_PATH_RSS_METHODS.'/catalog/category';
00166 if((bool)Mage::getStoreConfig($path)){
00167 $category = Mage::getModel('catalog/category');
00168
00169
00170 $treeModel = $category->getTreeModel()->loadNode(Mage::app()->getStore()->getRootCategoryId());
00171 $nodes = $treeModel->loadChildren()->getChildren();
00172
00173 $nodeIds = array();
00174 foreach ($nodes as $node) {
00175 $nodeIds[] = $node->getId();
00176 }
00177
00178 $collection = $category->getCollection()
00179 ->addAttributeToSelect('url_key')
00180 ->addAttributeToSelect('name')
00181 ->addAttributeToSelect('is_anchor')
00182 ->addAttributeToFilter('is_active',1)
00183 ->addIdFilter($nodeIds)
00184 ->addAttributeToSort('name')
00185 ->load();
00186
00187 foreach ($collection as $category) {
00188 $this->addRssFeed('rss/catalog/category', $category->getName(),array('cid'=>$category->getId()));
00189 }
00190 }
00191 }
00192 }