1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class extends Mage_Core_Block_Template
35: {
36:
37: 38: 39: 40: 41:
42: const CACHE_TAG = 'block_html_rss_order_new';
43:
44: protected function _construct()
45: {
46: $this->setCacheTags(array(self::CACHE_TAG));
47: 48: 49:
50: $this->setCacheKey('rss_order_new');
51: $this->setCacheLifetime(600);
52: }
53:
54: protected function _toHtml()
55: {
56: $order = Mage::getModel('sales/order');
57: $passDate = $order->getResource()->formatDate(mktime(0,0,0,date('m'),date('d')-7));
58:
59: $newurl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order', array('_secure' => true, '_nosecret' => true));
60: $title = Mage::helper('rss')->__('New Orders');
61:
62: $rssObj = Mage::getModel('rss/rss');
63: $data = array('title' => $title,
64: 'description' => $title,
65: 'link' => $newurl,
66: 'charset' => 'UTF-8',
67: );
68: $rssObj->_addHeader($data);
69:
70: $collection = $order->getCollection()
71: ->addAttributeToFilter('created_at', array('date'=>true, 'from'=> $passDate))
72: ->addAttributeToSort('created_at','desc')
73: ;
74:
75: $detailBlock = Mage::getBlockSingleton('rss/order_details');
76:
77: Mage::dispatchEvent('rss_order_new_collection_select', array('collection' => $collection));
78:
79: Mage::getSingleton('core/resource_iterator')
80: ->walk($collection->getSelect(), array(array($this, 'addNewOrderXmlCallback')), array('rssObj'=> $rssObj, 'order'=>$order , 'detailBlock' => $detailBlock));
81:
82: return $rssObj->createRssXml();
83: }
84:
85: public function addNewOrderXmlCallback($args)
86: {
87: $rssObj = $args['rssObj'];
88: $order = $args['order'];
89: $detailBlock = $args['detailBlock'];
90: $order->reset()->load($args['row']['entity_id']);
91: if ($order && $order->getId()) {
92: $title = Mage::helper('rss')->__('Order #%s created at %s', $order->getIncrementId(), $this->formatDate($order->getCreatedAt()));
93: $url = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view', array('_secure' => true, 'order_id' => $order->getId(), '_nosecret' => true));
94: $detailBlock->setOrder($order);
95: $data = array(
96: 'title' => $title,
97: 'link' => $url,
98: 'description' => $detailBlock->toHtml()
99: );
100: $rssObj->_addEntry($data);
101: }
102: }
103: }
104: