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_XmlConnect
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: * Customer orders history xml renderer
29: *
30: * @category Mage
31: * @package Mage_XmlConnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Block_Customer_Order_List extends Mage_Core_Block_Template
35: {
36: /**
37: * Orders count limit
38: */
39: const ORDERS_LIST_LIMIT = 10;
40:
41: /**
42: * Render customer orders list xml
43: *
44: * @return string
45: */
46: protected function _toHtml()
47: {
48: $ordersXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<orders></orders>');
49:
50: $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter(
51: 'customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId()
52: )
53: ->addFieldToFilter(
54: 'state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates())
55: )
56: ->setOrder('created_at', 'desc');
57:
58: $orders->getSelect()->limit(self::ORDERS_LIST_LIMIT, 0);
59: $orders->load();
60:
61: if (sizeof($orders->getItems())) {
62: foreach ($orders as $_order) {
63: $item = $ordersXmlObj->addChild('item');
64: $item->addChild('entity_id', $_order->getId());
65: $item->addChild('number', $_order->getRealOrderId());
66: $item->addChild('date', $this->formatDate($_order->getCreatedAtStoreDate()));
67: if ($_order->getShippingAddress()) {
68: $item->addChild('ship_to', $ordersXmlObj->escapeXml($_order->getShippingAddress()->getName()));
69: }
70: $item->addChild('total', $_order->getOrderCurrency()->formatPrecision(
71: $_order->getGrandTotal(), 2, array(), false, false
72: ));
73: $item->addChild('status', $_order->getStatusLabel());
74: }
75: }
76: return $ordersXmlObj->asNiceXml();
77: }
78: }
79: