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_Item_Renderer_Bundle extends Mage_Bundle_Block_Sales_Order_Items_Renderer
35: {
36: 37: 38: 39: 40: 41: 42:
43: public function addItemToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderItemXmlObj)
44: {
45:
46: $parentItem = $this->getItem();
47: $items = array_merge(array($parentItem), $parentItem->getChildrenItems());
48: $_prevOptionId = '';
49:
50:
51: $weeeHelper = $this->helper('weee');
52:
53: $taxHelper = $this->helper('tax');
54:
55:
56: $itemXml = $orderItemXmlObj->addChild('item');
57:
58: $optionsXml = $itemXml->addChild('related_products');
59:
60: $this->setWeeeTaxAppliedAmount($parentItem->getWeeeTaxAppliedAmount());
61: $this->setWeeeTaxDisposition($parentItem->getWeeeTaxDisposition());
62:
63: $typeOfDisplay1 = $weeeHelper->typeOfDisplay($parentItem, 1, 'sales')
64: && $this->getWeeeTaxAppliedAmount();
65: $typeOfDisplay2 = $weeeHelper->typeOfDisplay($parentItem, 2, 'sales')
66: && $this->getWeeeTaxAppliedAmount();
67: $typeOfDisplay4 = $weeeHelper->typeOfDisplay($parentItem, 4, 'sales')
68: && $this->getWeeeTaxAppliedAmount();
69: $typeOfDisplay014 = $weeeHelper->typeOfDisplay($parentItem, array(0, 1, 4), 'sales')
70: && $this->getWeeeTaxAppliedAmount();
71:
72: $this->setTypesOfDisplay(array(
73: Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_1 => $typeOfDisplay1,
74: Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_2 => $typeOfDisplay2,
75: Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_4 => $typeOfDisplay4,
76: Mage_XmlConnect_Helper_Customer_Order::PRICE_DISPLAY_TYPE_14 => $typeOfDisplay014,
77: ));
78: $this->setWeeeTaxes($weeeHelper->getApplied($parentItem));
79:
80:
81: foreach ($items as $item) {
82: $isOption = $item->getParentItem() ? true : false;
83:
84:
85: if ($isOption) {
86: $objectXml = $optionsXml->addChild('item');
87: } else {
88: $objectXml = $itemXml;
89: }
90: $objectXml->addAttribute('product_id', $item->getProductId());
91: $objectXml->addCustomChild('entity_type', $item->getProductType());
92:
93: if ($isOption) {
94: $attributes = $this->getSelectionAttributes($item);
95: if ($_prevOptionId != $attributes['option_id']) {
96: $objectXml->addAttribute('label', $objectXml->xmlAttribute($attributes['option_label']));
97: $_prevOptionId = $attributes['option_id'];
98: }
99: }
100:
101: $objectXml->addCustomChild('sku', Mage::helper('core/string')->splitInjection($item->getSku()));
102:
103: if ($isOption) {
104: $name = $this->getValueHtml($item);
105: } else {
106: $name = $item->getName();
107: }
108: $objectXml->addCustomChild('name', $name);
109:
110:
111: if (!$isOption) {
112:
113: $priceXml = $objectXml->addChild('price');
114:
115: $subtotalXml = $objectXml->addChild('subtotal');
116:
117:
118: if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceExclTax()) {
119: Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
120: $this,
121: $parentItem,
122: $priceXml,
123: $subtotalXml
124: );
125: }
126:
127:
128: if ($taxHelper->displaySalesBothPrices() || $taxHelper->displaySalesPriceInclTax()) {
129: Mage::helper('xmlconnect/customer_order')->addPriceAndSubtotalToXml(
130: $this, $parentItem, $priceXml, $subtotalXml, true
131: );
132: }
133: }
134:
135:
136:
137: if (($isOption && $this->isChildCalculated())
138: || (!$isOption && !$this->isChildCalculated())
139: ) {
140: $qtyXml = $objectXml->addChild('qty');
141: if ($item->getQtyOrdered() > 0) {
142: $qtyXml->addCustomChild('value', $item->getQtyOrdered() * 1, array(
143: 'label' => Mage::helper('sales')->__('Ordered')
144: ));
145: }
146: if ($item->getQtyShipped() > 0 && !$this->isShipmentSeparately()) {
147: $qtyXml->addCustomChild('value', $item->getQtyShipped() * 1, array(
148: 'label' => Mage::helper('sales')->__('Shipped')
149: ));
150: }
151: if ($item->getQtyCanceled() > 0) {
152: $qtyXml->addCustomChild('value', $item->getQtyCanceled() * 1, array(
153: 'label' => Mage::helper('sales')->__('Canceled')
154: ));
155: }
156: if ($item->getQtyRefunded() > 0) {
157: $qtyXml->addCustomChild('value', $item->getQtyRefunded() * 1, array(
158: 'label' => Mage::helper('sales')->__('Refunded')
159: ));
160: }
161: } elseif ($item->getQtyShipped() > 0 && $isOption && $this->isShipmentSeparately()) {
162: $qtyXml = $objectXml->addChild('qty');
163: $qtyXml->addCustomChild('value', $item->getQtyShipped() * 1, array(
164: 'label' => Mage::helper('sales')->__('Shipped')
165: ));
166: }
167: }
168:
169: if ($parentItem->getDescription()) {
170: $itemXml->addCustomChild('description', $parentItem->getDescription());
171: }
172:
173: Mage::helper('xmlconnect/customer_order')->addItemOptionsToXml($this, $itemXml);
174: }
175:
176: 177: 178: 179: 180: 181:
182: public function getValueHtml($item)
183: {
184: $attributes = $this->getSelectionAttributes($item);
185: if ($attributes) {
186: return sprintf('%d', $attributes['qty']) . ' x ' . $item->getName() . ' - '
187: . $this->_formatPrice($attributes['price']);
188: } else {
189: return $item->getName();
190: }
191: }
192:
193: 194: 195: 196: 197: 198:
199: protected function _formatPrice($price)
200: {
201: return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $price);
202: }
203: }
204: