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_Order_New extends Mage_Core_Block_Template
00035 {
00036 protected function _construct()
00037 {
00038
00039
00040
00041 $this->setCacheKey('rss_order_new');
00042 $this->setCacheLifetime(600);
00043 }
00044
00045 protected function _toHtml()
00046 {
00047 $order = Mage::getModel('sales/order');
00048 $passDate = $order->getResource()->formatDate(mktime(0,0,0,date('m'),date('d')-7));
00049
00050 $newurl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order', array('_secure' => true, '_nosecret' => true));
00051 $title = Mage::helper('rss')->__('New Orders');
00052
00053 $rssObj = Mage::getModel('rss/rss');
00054 $data = array('title' => $title,
00055 'description' => $title,
00056 'link' => $newurl,
00057 'charset' => 'UTF-8',
00058 );
00059 $rssObj->_addHeader($data);
00060
00061 $collection = $order->getCollection()
00062 ->addAttributeToFilter('created_at', array('date'=>true, 'from'=> $passDate))
00063 ->addAttributeToSort('created_at','desc')
00064 ;
00065
00066 $detailBlock = Mage::getBlockSingleton('rss/order_details');
00067 Mage::getSingleton('core/resource_iterator')
00068 ->walk($collection->getSelect(), array(array($this, 'addNewOrderXmlCallback')), array('rssObj'=> $rssObj, 'order'=>$order , 'detailBlock' => $detailBlock));
00069
00070 return $rssObj->createRssXml();
00071 }
00072
00073 public function addNewOrderXmlCallback($args)
00074 {
00075 $rssObj = $args['rssObj'];
00076 $order = $args['order'];
00077 $detailBlock = $args['detailBlock'];
00078 $order->unsetData()->load($args['row']['entity_id']);
00079 if ($order && $order->getId()) {
00080 $title = Mage::helper('rss')->__('Order #%s created at %s', $order->getIncrementId(), $this->formatDate($order->getCreatedAt()));
00081 $url = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view', array('_secure' => true, 'order_id' => $order->getId(), '_nosecret' => true));
00082 $detailBlock->setOrder($order);
00083 $data = array(
00084 'title' => $title,
00085 'link' => $url,
00086 'description' => $detailBlock->toHtml()
00087 );
00088 $rssObj->_addEntry($data);
00089 }
00090 }
00091 }