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_Helper_Customer_Order extends Mage_Core_Helper_Abstract
35: {
36: 37: 38: 39:
40: const PRICE_DISPLAY_TYPE_1 = 1;
41: const PRICE_DISPLAY_TYPE_2 = 2;
42: const PRICE_DISPLAY_TYPE_4 = 4;
43: const PRICE_DISPLAY_TYPE_14 = 14;
44:
45:
46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function addPriceAndSubtotalToXml(Mage_Core_Block_Template $renderer, Mage_Sales_Model_Order_Item $item,
57: Mage_XmlConnect_Model_Simplexml_Element $priceXml, Mage_XmlConnect_Model_Simplexml_Element $subtotalXml,
58: $isIncludeTax = false
59: ) {
60: $weeeParams = array();
61:
62: $typesOfDisplay = $renderer->getTypesOfDisplay();
63: if ($isIncludeTax) {
64: $nodeName = 'including_tax';
65: $nodeLabel = Mage::helper('tax')->__('Incl. Tax');
66:
67: $inclPrice = $renderer->helper('checkout')->getPriceInclTax($item);
68: $inclSubtotal = $renderer->helper('checkout')->getSubtotalInclTax($item);
69:
70: if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_14]) {
71: $price = $inclPrice + $renderer->getWeeeTaxAppliedAmount();
72: $subtotal = $inclSubtotal + $item->getWeeeTaxAppliedRowAmount();
73: } else {
74: $price = $inclPrice - $renderer->getWeeeTaxDisposition();
75: $subtotal = $inclSubtotal - $item->getWeeeTaxRowDisposition();
76: }
77: $weeeParams['include'] = $inclPrice;
78: } else {
79: $nodeName = 'excluding_tax';
80: $nodeLabel = Mage::helper('tax')->__('Excl. Tax');
81:
82: if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_14]) {
83: $price = $item->getPrice() + $renderer->getWeeeTaxAppliedAmount()
84: + $renderer->getWeeeTaxDisposition();
85: $subtotal = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount()
86: + $item->getWeeeTaxRowDisposition();
87: } else {
88: $price = $item->getPrice();
89: $subtotal = $item->getRowTotal();
90: }
91: }
92:
93: $configNode = array(
94: 'value' => $this->formatPrice($renderer, $price)
95: );
96: if ($renderer->helper('tax')->displaySalesBothPrices()) {
97: $configNode['label'] = $nodeLabel;
98: }
99:
100: $this->addWeeeTaxesToPriceXml(
101: $renderer, $item, $priceXml->addCustomChild($nodeName, null, $configNode), $weeeParams
102: );
103:
104: $configNode['value'] = $this->formatPrice($renderer, $subtotal);
105: $weeeParams['include'] = $isIncludeTax ? $inclSubtotal : null;
106: $weeeParams['is_subtotal'] = true;
107: $this->addWeeeTaxesToPriceXml(
108: $renderer, $item, $subtotalXml->addCustomChild($nodeName, null, $configNode), $weeeParams
109: );
110: }
111:
112: 113: 114: 115: 116: 117: 118:
119: public function addItemOptionsToXml(Mage_Core_Block_Template $renderer,
120: Mage_XmlConnect_Model_Simplexml_Element $itemXml
121: ) {
122: $options = $renderer->getItemOptions();
123: if (!empty($options)) {
124: $optionsXml = $itemXml->addChild('options');
125:
126: foreach ($options as $option) {
127: $value = false;
128: $formatedOptionValue = $renderer->getFormatedOptionValue($option);
129: if (isset($formatedOptionValue['full_view']) && isset($formatedOptionValue['value'])) {
130: $value = $formatedOptionValue['value'];
131: } elseif (isset($option['print_value'])) {
132: $value = $option['print_value'];
133: } elseif (isset($option['value'])) {
134: $value = $option['value'];
135: }
136: if ($value) {
137: $optionsXml->addCustomChild('option', strip_tags($value), array('label' => $option['label']));
138: }
139: }
140: }
141: }
142:
143: 144: 145: 146: 147: 148: 149: 150: 151:
152: public function addWeeeTaxesToPriceXml(Mage_Core_Block_Template $renderer, Mage_Sales_Model_Order_Item $item,
153: Mage_XmlConnect_Model_Simplexml_Element $parentXml, $params = array()
154: ) {
155: $weeTaxes = $renderer->getWeeeTaxes();
156: if (empty($weeTaxes)) {
157: return;
158: }
159:
160: $typesOfDisplay = $renderer->getTypesOfDisplay();
161:
162: $row = isset($params['is_subtotal']) && $params['is_subtotal'] ? 'row_' : '';
163:
164:
165: if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_1]) {
166: $weeeXml = $parentXml->addChild('weee');
167: foreach ($weeTaxes as $tax) {
168: $weeeXml->addCustomChild('tax', $this->formatPrice($renderer, $tax[$row . 'amount']),
169: array('label' => $tax['title'])
170: );
171: }
172: } elseif ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2] || $typesOfDisplay[self::PRICE_DISPLAY_TYPE_4]) {
173: $weeeXml = $parentXml->addChild('weee');
174: foreach ($weeTaxes as $tax) {
175: $weeeXml->addCustomChild('tax', $this->formatPrice($renderer, $tax[$row . 'amount_incl_tax']),
176: array('label' => $tax['title'])
177: );
178: }
179: }
180:
181: if ($typesOfDisplay[self::PRICE_DISPLAY_TYPE_2]) {
182: if (!is_null($params['include'])) {
183:
184: if (isset($params['is_subtotal'])) {
185: $total = $params['include'] + $item->getWeeeTaxAppliedRowAmount();
186: } else {
187: $total = $params['include'] + $renderer->getWeeeTaxAppliedAmount();
188: }
189: } else {
190:
191: if ($params['is_subtotal']) {
192: $total = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount()
193: + $item->getWeeeTaxRowDisposition();
194: } else {
195: $total = $item->getPrice() + $renderer->getWeeeTaxAppliedAmount()
196: + $renderer->getWeeeTaxDisposition();
197: }
198: }
199:
200: if (!isset($weeeXml)) {
201: $weeeXml = $parentXml->addChild('weee');
202: }
203: $weeeXml->addCustomChild(
204: 'total',
205: $this->formatPrice($renderer, $total),
206: array('label' => $renderer->helper('weee')->__('Total'))
207: );
208: }
209: }
210:
211: 212: 213: 214: 215: 216: 217: 218:
219: public function addQuantityToXml(Mage_Core_Block_Template $renderer,
220: Mage_XmlConnect_Model_Simplexml_Element $quantityXml, Mage_Sales_Model_Order_Item $item
221: ) {
222: $qty = 1 * $item->getQtyOrdered();
223: if ($qty > 0) {
224: $quantityXml->addCustomChild('value', $qty, array('label' => Mage::helper('xmlconnect')->__('Ordered')));
225: }
226: $qty = 1 * $item->getQtyShipped();
227: if ($qty > 0) {
228: $quantityXml->addCustomChild('value', $qty, array('label' => Mage::helper('xmlconnect')->__('Shipped')));
229: }
230: $qty = 1 * $item->getQtyCanceled();
231: if ($qty > 0) {
232: $quantityXml->addCustomChild('value', $qty, array('label' => Mage::helper('xmlconnect')->__('Canceled')));
233: }
234: $qty = 1 * $item->getQtyRefunded();
235: if ($qty > 0) {
236: $quantityXml->addCustomChild('value', $qty, array('label' => Mage::helper('xmlconnect')->__('Refunded')));
237: }
238: }
239:
240: 241: 242: 243: 244: 245: 246:
247: public function formatPrice(Mage_Core_Block_Template $renderer, $price)
248: {
249: return $renderer->getOrder()->getOrderCurrency()->formatPrecision($price, 2, array(), false);
250: }
251: }
252: