Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Adminhtml_Rss_CatalogController
  • Mage_Adminhtml_Rss_OrderController
  • Mage_Rss_Block_Abstract
  • Mage_Rss_Block_Catalog_Abstract
  • Mage_Rss_Block_Catalog_Category
  • Mage_Rss_Block_Catalog_New
  • Mage_Rss_Block_Catalog_NotifyStock
  • Mage_Rss_Block_Catalog_Review
  • Mage_Rss_Block_Catalog_Salesrule
  • Mage_Rss_Block_Catalog_Special
  • Mage_Rss_Block_Catalog_Tag
  • Mage_Rss_Block_List
  • Mage_Rss_Block_Order_Details
  • Mage_Rss_Block_Order_New
  • Mage_Rss_Block_Order_Status
  • Mage_Rss_Block_Wishlist
  • Mage_Rss_CatalogController
  • Mage_Rss_Helper_Catalog
  • Mage_Rss_Helper_Data
  • Mage_Rss_Helper_Order
  • Mage_Rss_IndexController
  • Mage_Rss_Model_Mysql4_Order
  • Mage_Rss_Model_Observer
  • Mage_Rss_Model_Resource_Order
  • Mage_Rss_Model_Rss
  • Mage_Rss_Model_Session
  • Mage_Rss_Model_System_Config_Backend_Links
  • Mage_Rss_OrderController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Rss
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Review form block
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Rss
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Rss_Block_Catalog_Special extends Mage_Rss_Block_Catalog_Abstract
 35: {
 36:     /**
 37:      * Zend_Date object for date comparsions
 38:      *
 39:      * @var Zend_Date $_currentDate
 40:      */
 41:     protected static $_currentDate = null;
 42: 
 43:     protected function _construct()
 44:     {
 45:         /*
 46:         * setting cache to save the rss for 10 minutes
 47:         */
 48:         $this->setCacheKey('rss_catalog_special_'.$this->_getStoreId().'_'.$this->_getCustomerGroupId());
 49:         $this->setCacheLifetime(600);
 50:     }
 51: 
 52:     protected function _toHtml()
 53:     {
 54:          //store id is store view id
 55:         $storeId = $this->_getStoreId();
 56:         $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
 57: 
 58:         //customer group id
 59:         $customerGroupId = $this->_getCustomerGroupId();
 60: 
 61:         $product = Mage::getModel('catalog/product');
 62: 
 63:         $fields = array(
 64:             'final_price',
 65:             'price'
 66:         );
 67:         $specials = $product->setStoreId($storeId)->getResourceCollection()
 68:             ->addPriceDataFieldFilter('%s < %s', $fields)
 69:             ->addPriceData($customerGroupId, $websiteId)
 70:             ->addAttributeToSelect(
 71:                     array(
 72:                         'name', 'short_description', 'description', 'price', 'thumbnail',
 73:                         'special_price', 'special_to_date',
 74:                         'msrp_enabled', 'msrp_display_actual_price_type', 'msrp'
 75:                     ),
 76:                     'left'
 77:             )
 78:             ->addAttributeToSort('name', 'asc')
 79:         ;
 80: 
 81:         $newurl = Mage::getUrl('rss/catalog/special/store_id/' . $storeId);
 82:         $title = Mage::helper('rss')->__('%s - Special Products', Mage::app()->getStore()->getFrontendName());
 83:         $lang = Mage::getStoreConfig('general/locale/code');
 84: 
 85:         $rssObj = Mage::getModel('rss/rss');
 86:         $data = array('title' => $title,
 87:                 'description' => $title,
 88:                 'link'        => $newurl,
 89:                 'charset'     => 'UTF-8',
 90:                 'language'    => $lang
 91:                 );
 92:         $rssObj->_addHeader($data);
 93: 
 94:         $results = array();
 95:         /*
 96:         using resource iterator to load the data one by one
 97:         instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
 98:         */
 99:         Mage::getSingleton('core/resource_iterator')->walk(
100:             $specials->getSelect(),
101:             array(array($this, 'addSpecialXmlCallback')),
102:             array('rssObj'=> $rssObj, 'results'=> &$results)
103:         );
104: 
105:         if (sizeof($results)>0) {
106:             foreach($results as $result){
107:                 // render a row for RSS feed
108:                 $product->setData($result);
109:                 $html = sprintf('<table><tr>
110:                     <td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>
111:                     <td style="text-decoration:none;">%s',
112:                     $product->getProductUrl(),
113:                     $this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75),
114:                     $this->helper('catalog/output')->productAttribute(
115:                         $product,
116:                         $product->getDescription(),
117:                         'description'
118:                     )
119:                 );
120: 
121:                 // add price data if needed
122:                 if ($product->getAllowedPriceInRss()) {
123:                     if (Mage::helper('catalog')->canApplyMsrp($product)) {
124:                         $html .= '<br/><a href="' . $product->getProductUrl() . '">'
125:                             . $this->__('Click for price') . '</a>';
126:                     } else {
127:                         $special = '';
128:                         if ($result['use_special']) {
129:                             $special = '<br />' . Mage::helper('catalog')->__('Special Expires On: %s', $this->formatDate($result['special_to_date'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM));
130:                         }
131:                         $html .= sprintf('<p>%s %s%s</p>',
132:                             Mage::helper('catalog')->__('Price: %s', Mage::helper('core')->currency($result['price'])),
133:                             Mage::helper('catalog')->__('Special Price: %s', Mage::helper('core')->currency($result['final_price'])),
134:                             $special
135:                         );
136:                     }
137:                 }
138: 
139:                 $html .= '</td></tr></table>';
140: 
141:                 $rssObj->_addEntry(array(
142:                     'title'       => $product->getName(),
143:                     'link'        => $product->getProductUrl(),
144:                     'description' => $html
145:                 ));
146:             }
147:         }
148:         return $rssObj->createRssXml();
149:     }
150: 
151:     /**
152:      * Preparing data and adding to rss object
153:      *
154:      * @param array $args
155:      */
156:     public function addSpecialXmlCallback($args)
157:     {
158:         if (!isset(self::$_currentDate)) {
159:             self::$_currentDate = new Zend_Date();
160:         }
161: 
162:         // dispatch event to determine whether the product will eventually get to the result
163:         $product = new Varien_Object(array('allowed_in_rss' => true, 'allowed_price_in_rss' => true));
164:         $args['product'] = $product;
165:         Mage::dispatchEvent('rss_catalog_special_xml_callback', $args);
166:         if (!$product->getAllowedInRss()) {
167:             return;
168:         }
169: 
170:         // add row to result and determine whether special price is active (less or equal to the final price)
171:         $row = $args['row'];
172:         $row['use_special'] = false;
173:         $row['allowed_price_in_rss'] = $product->getAllowedPriceInRss();
174:         if (isset($row['special_to_date']) && $row['final_price'] <= $row['special_price']
175:             && $row['allowed_price_in_rss']
176:         ) {
177:             $compareDate = self::$_currentDate->compareDate($row['special_to_date'], Varien_Date::DATE_INTERNAL_FORMAT);
178:             if (-1 === $compareDate || 0 === $compareDate) {
179:                 $row['use_special'] = true;
180:             }
181:         }
182: 
183:        $args['results'][] = $row;
184:     }
185: 
186: 
187:     /**
188:      * Function for comparing two items in collection
189:      *
190:      * @param   Varien_Object $item1
191:      * @param   Varien_Object $item2
192:      * @return  boolean
193:      */
194:     public function sortByStartDate($a, $b)
195:     {
196:         return $a['start_date']>$b['start_date'] ? -1 : ($a['start_date']<$b['start_date'] ? 1 : 0);
197:     }
198: }
199: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0