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 Mage_XmlConnect_Block_Customer_Order_Details extends Mage_Payment_Block_Info
35: {
36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
52: protected $_methodArray = array(
53: 'ccsave', 'checkmo', 'purchaseorder', 'authorizenet', 'pbridge_authorizenet', 'pbridge_verisign',
54: 'paypal_express', 'paypal_mecl', 'pbridge_paypal_direct', 'pbridge_paypaluk_direct', 'free'
55: );
56:
57: 58: 59: 60: 61:
62: protected function _toHtml()
63: {
64:
65: $orderXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<order_details></order_details>');
66:
67: $order = $this->_getOrder();
68:
69: $orderDate = $this->formatDate($order->getCreatedAtStoreDate(), 'long');
70: $orderXmlObj->addCustomChild('order', null, array(
71: 'label' => $this->__('Order #%s - %s', $order->getRealOrderId(), $order->getStatusLabel()),
72: 'order_date' => $this->__('Order Date: %s', $orderDate)
73: ));
74: if (!$order->getIsVirtual()) {
75: $shipping = Mage::helper('xmlconnect')->trimLineBreaks($order->getShippingAddress()->format('text'));
76: $billing = Mage::helper('xmlconnect')->trimLineBreaks($order->getBillingAddress()->format('text'));
77:
78: $orderXmlObj->addCustomChild('shipping_address', $shipping);
79: $orderXmlObj->addCustomChild('billing_address', $billing);
80:
81: if ($order->getShippingDescription()) {
82: $shippingMethodDescription = $order->getShippingDescription();
83: } else {
84: $shippingMethodDescription = Mage::helper('sales')->__('No shipping information available');
85: }
86: $orderXmlObj->addCustomChild('shipping_method', $shippingMethodDescription);
87: }
88:
89: $this->_addPaymentMethodInfoToXmlObj($orderXmlObj);
90:
91: $itemsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.items');
92: if ($itemsBlock) {
93:
94: $itemsBlock->setItems($order->getItemsCollection());
95: $itemsBlock->addItemsToXmlObject($orderXmlObj);
96: $totalsBlock = $this->getLayout()->getBlock('xmlconnect.customer.order.totals');
97: if ($totalsBlock) {
98: $totalsBlock->setOrder($order);
99: $totalsBlock->addTotalsToXmlObject($orderXmlObj);
100: }
101: } else {
102: $orderXmlObj->addChild('ordered_items');
103: }
104:
105: return $orderXmlObj->asNiceXml();
106: }
107:
108: 109: 110: 111: 112: 113:
114: protected function _addPaymentMethodInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj)
115: {
116: $order = $this->_getOrder();
117:
118:
119: $method = $this->helper('payment')->getInfoBlock($order->getPayment())->getMethod();
120: $methodCode = $method->getCode();
121:
122: $paymentNode = $orderXmlObj->addChild('payment_method');
123:
124: if (in_array($methodCode, $this->_methodArray, true)) {
125: $currentBlockRenderer = 'xmlconnect/checkout_payment_method_info_' . $methodCode;
126: $currentBlockName = 'xmlconnect.checkout.payment.method.info.' . $methodCode;
127: $this->getLayout()->addBlock($currentBlockRenderer, $currentBlockName);
128: $this->setChild($methodCode, $currentBlockName);
129: $renderer = $this->getChild($methodCode)->setInfo($order->getPayment());
130: $renderer->addPaymentInfoToXmlObj($paymentNode);
131: } else {
132: $paymentNode->addAttribute('type', $methodCode);
133: $paymentNode->addAttribute('title', $orderXmlObj->xmlAttribute($method->getTitle()));
134:
135: $this->setInfo($order->getPayment());
136:
137: $specificInfo = array_merge(
138: (array)$order->getPayment()->getAdditionalInformation(),
139: (array)$this->getSpecificInformation()
140: );
141: if (!empty($specificInfo)) {
142: foreach ($specificInfo as $label => $value) {
143: if ($value) {
144: $paymentNode->addCustomChild('item', implode($this->getValueAsArray($value, true), '\n'),
145: array('label' => $label)
146: );
147: }
148: }
149: }
150: }
151:
152: return $orderXmlObj;
153: }
154:
155: 156: 157: 158: 159: 160:
161: protected function _getOrder()
162: {
163: $order = Mage::registry('current_order');
164: if (!($order instanceof Mage_Sales_Model_Order)) {
165: Mage::throwException($this->__('Order is not available.'));
166: }
167: return $order;
168: }
169:
170: 171: 172: 173: 174: 175: 176:
177: protected function _formatAddress($address)
178: {
179: return preg_replace(
180: array('@\r@', '@\n+@'),
181: array('', '\n'),
182: $address
183: );
184: }
185: }
186: