Mage_Rss_Block_Catalog_Special Class Reference

Inheritance diagram for Mage_Rss_Block_Catalog_Special:

Mage_Rss_Block_Abstract Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 addSpecialXmlCallback ($args)
 sortByStartDate ($a, $b)

Protected Member Functions

 _construct ()
 _toHtml ()


Detailed Description

Definition at line 34 of file Special.php.


Member Function Documentation

_construct (  )  [protected]

Internal constructor, that is called from real constructor

Please override this one instead of overriding real __construct constructor

Please override this one instead of overriding real __construct constructor

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 36 of file Special.php.

00037     {
00038         /*
00039         * setting cache to save the rss for 10 minutes
00040         */
00041         $this->setCacheKey('rss_catalog_special_'.$this->getStoreId().'_'.$this->_getCustomerGroupId());
00042         $this->setCacheLifetime(600);
00043     }

_toHtml (  )  [protected]

Render block HTML

Returns:
string

Reimplemented from Mage_Core_Block_Template.

Definition at line 45 of file Special.php.

00046     {
00047          //store id is store view id
00048         $storeId = $this->_getStoreId();
00049         $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
00050 
00051         //customer group id
00052         $custGroup =   $this->_getCustomerGroupId();
00053 
00054         $product = Mage::getModel('catalog/product');
00055         $todayDate = $product->getResource()->formatDate(time());
00056 
00057         $rulePriceWhere = "({{table}}.rule_date is null) or ({{table}}.rule_date='$todayDate' and {{table}}.website_id='$websiteId' and {{table}}.customer_group_id='$custGroup')";
00058 
00059         $specials = $product->setStoreId($storeId)->getResourceCollection()
00060             ->addAttributeToFilter('special_price', array('gt'=>0), 'left')
00061             ->addAttributeToFilter('special_from_date', array('date'=>true, 'to'=> $todayDate), 'left')
00062             ->addAttributeToFilter(array(
00063                 array('attribute'=>'special_to_date', 'date'=>true, 'from'=>$todayDate),
00064                 array('attribute'=>'special_to_date', 'is' => new Zend_Db_Expr('null'))
00065             ), '', 'left')
00066             ->addAttributeToSort('special_from_date', 'desc')
00067             ->addAttributeToSelect(array('name', 'short_description', 'description', 'price', 'thumbnail', 'special_to_date'), 'inner')
00068             ->joinTable('catalogrule/rule_product_price', 'product_id=entity_id', array('rule_price'=>'rule_price', 'rule_start_date'=>'latest_start_date'), $rulePriceWhere, 'left')
00069         ;
00070 
00071 //public function join($table, $cond, $cols='*')
00072         $rulePriceCollection = Mage::getResourceModel('catalogrule/rule_product_price_collection')
00073             ->addFieldToFilter('website_id', $websiteId)
00074             ->addFieldToFilter('customer_group_id', $custGroup)
00075             ->addFieldToFilter('rule_date', $todayDate)
00076         ;
00077 //echo $rulePriceCollection->getSelect();
00078         $productIds = $rulePriceCollection->getProductIds();
00079 
00080         if (!empty($productIds)) {
00081             $specials->getSelect()->orWhere('e.entity_id in ('.implode(',',$productIds).')');
00082         }
00083 
00084         /*
00085         *need to put status and visibility after orWhere clause for catalog price rule products
00086         */
00087         Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($specials);
00088         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($specials);
00089 
00090 
00091 //echo $specials->getSelect();
00092 
00093         $newurl = Mage::getUrl('rss/catalog/new');
00094         $title = Mage::helper('rss')->__('%s - Special Discounts', Mage::app()->getStore()->getName());
00095         $lang = Mage::getStoreConfig('general/locale/code');
00096 
00097         $rssObj = Mage::getModel('rss/rss');
00098         $data = array('title' => $title,
00099                 'description' => $title,
00100                 'link'        => $newurl,
00101                 'charset'     => 'UTF-8',
00102                 'language'    => $lang
00103                 );
00104         $rssObj->_addHeader($data);
00105 
00106         $results = array();
00107         /*
00108         using resource iterator to load the data one by one
00109         instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
00110         */
00111         Mage::getSingleton('core/resource_iterator')
00112             ->walk($specials->getSelect(), array(array($this, 'addSpecialXmlCallback')), array('rssObj'=> $rssObj, 'results'=> &$results));
00113 
00114         if(sizeof($results)>0){
00115            usort($results, array(&$this, 'sortByStartDate'));
00116            foreach($results as $result){
00117                $product->setData($result);
00118                //$product->unsetData()->load($result['entity_id']);
00119 
00120                $special_price = ($result['use_special'] ? $result['special_price'] : $result['rule_price']);
00121                $description = '<table><tr>'.
00122                 '<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>'.
00123                 '<td  style="text-decoration:none;">'.$product->getDescription().
00124                 '<p> Price:'.Mage::helper('core')->currency($product->getPrice()).
00125                 ' Special Price:'. Mage::helper('core')->currency($special_price).
00126                 ($result['use_special'] && $result['special_to_date'] ? '<br/> Special Expires on: '.$this->formatDate($result['special_to_date'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM) : '').
00127                 '</p>'.
00128                 '</td>'.
00129                 '</tr></table>';
00130                 $data = array(
00131                         'title'         => $product->getName(),
00132                         'link'          => $product->getProductUrl(),
00133                         'description'   => $description,
00134 
00135                         );
00136                 $rssObj->_addEntry($data);
00137            }
00138         }
00139         return $rssObj->createRssXml();
00140     }

addSpecialXmlCallback ( args  ) 

Definition at line 142 of file Special.php.

00143     {
00144 //echo "<pre>";
00145 //print_r($args['row']);
00146        $row = $args['row'];
00147        $special_price = $row['special_price'];
00148        $rule_price = $row['rule_price'];
00149        if (!$rule_price || ($rule_price && $special_price && $special_price<=$rule_price)) {
00150            $row['start_date'] = $row['special_from_date'];
00151            $row['use_special'] = true;
00152        } else {
00153            $row['start_date'] = $row['rule_start_date'];
00154            $row['use_special'] = false;
00155        }
00156        $args['results'][] = $row;
00157     }

sortByStartDate ( a,
b 
)

Function for comparing two items in collection

Parameters:
Varien_Object $item1
Varien_Object $item2
Returns:
boolean

Definition at line 167 of file Special.php.

00168     {
00169         return $a['start_date']>$b['start_date'] ? -1 : ($a['start_date']<$b['start_date'] ? 1 : 0);
00170     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:38 2009 for Magento by  doxygen 1.5.8