*/ class Mage_Rss_Block_Catalog_Special extends Mage_Rss_Block_Catalog_Abstract { /** * Zend_Date object for date comparsions * * @var Zend_Date $_currentDate */ protected static $_currentDate = null; protected function _construct() { /* * setting cache to save the rss for 10 minutes */ $this->setCacheKey('rss_catalog_special_'.$this->_getStoreId().'_'.$this->_getCustomerGroupId()); $this->setCacheLifetime(600); } protected function _toHtml() { //store id is store view id $storeId = $this->_getStoreId(); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); //customer group id $customerGroupId = $this->_getCustomerGroupId(); $product = Mage::getModel('catalog/product'); $fields = array( 'final_price', 'price' ); $specials = $product->setStoreId($storeId)->getResourceCollection() ->addPriceDataFieldFilter('%s < %s', $fields) ->addPriceData($customerGroupId, $websiteId) ->addAttributeToSelect( array( 'name', 'short_description', 'description', 'price', 'thumbnail', 'special_price', 'special_to_date', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp' ), 'left' ) ->addAttributeToSort('name', 'asc') ; $newurl = Mage::getUrl('rss/catalog/special/store_id/' . $storeId); $title = Mage::helper('rss')->__('%s - Special Products', Mage::app()->getStore()->getFrontendName()); $lang = Mage::getStoreConfig('general/locale/code'); $rssObj = Mage::getModel('rss/rss'); $data = array('title' => $title, 'description' => $title, 'link' => $newurl, 'charset' => 'UTF-8', 'language' => $lang ); $rssObj->_addHeader($data); $results = array(); /* using resource iterator to load the data one by one instead of loading all at the same time. loading all data at the same time can cause the big memory allocation. */ Mage::getSingleton('core/resource_iterator')->walk( $specials->getSelect(), array(array($this, 'addSpecialXmlCallback')), array('rssObj'=> $rssObj, 'results'=> &$results) ); if (sizeof($results)>0) { foreach($results as $result){ // render a row for RSS feed $product->setData($result); $html = sprintf('
%s',
$product->getProductUrl(),
$this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75),
$this->helper('catalog/output')->productAttribute(
$product,
$product->getDescription(),
'description'
)
);
// add price data if needed
if ($product->getAllowedPriceInRss()) {
if (Mage::helper('catalog')->canApplyMsrp($product)) {
$html .= ' ' . $this->__('Click for price') . ''; } else { $special = ''; if ($result['use_special']) { $special = ' ' . Mage::helper('catalog')->__('Special Expires On: %s', $this->formatDate($result['special_to_date'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)); } $html .= sprintf(' %s %s%s ', Mage::helper('catalog')->__('Price: %s', Mage::helper('core')->currency($result['price'])), Mage::helper('catalog')->__('Special Price: %s', Mage::helper('core')->currency($result['final_price'])), $special ); } } $html .= ' |