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:
35: class Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer extends Mage_Adminhtml_Block_Sales_Items_Renderer_Default
36: {
37: 38: 39: 40: 41: 42:
43: public function getChilds($item)
44: {
45: $_itemsArray = array();
46:
47: if ($item instanceof Mage_Sales_Model_Order_Invoice_Item) {
48: $_items = $item->getInvoice()->getAllItems();
49: } else if ($item instanceof Mage_Sales_Model_Order_Shipment_Item) {
50: $_items = $item->getShipment()->getAllItems();
51: } else if ($item instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
52: $_items = $item->getCreditmemo()->getAllItems();
53: }
54:
55: if ($_items) {
56: foreach ($_items as $_item) {
57: if ($parentItem = $_item->getOrderItem()->getParentItem()) {
58: $_itemsArray[$parentItem->getId()][$_item->getOrderItemId()] = $_item;
59: } else {
60: $_itemsArray[$_item->getOrderItem()->getId()][$_item->getOrderItemId()] = $_item;
61: }
62: }
63: }
64:
65: if (isset($_itemsArray[$item->getOrderItem()->getId()])) {
66: return $_itemsArray[$item->getOrderItem()->getId()];
67: } else {
68: return null;
69: }
70: }
71:
72: public function isShipmentSeparately($item = null)
73: {
74: if ($item) {
75: if ($item->getOrderItem()) {
76: $item = $item->getOrderItem();
77: }
78: if ($parentItem = $item->getParentItem()) {
79: if ($options = $parentItem->getProductOptions()) {
80: if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
81: return true;
82: } else {
83: return false;
84: }
85: }
86: } else {
87: if ($options = $item->getProductOptions()) {
88: if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
89: return false;
90: } else {
91: return true;
92: }
93: }
94: }
95: }
96:
97: if ($options = $this->getOrderItem()->getProductOptions()) {
98: if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
99: return true;
100: }
101: }
102: return false;
103: }
104:
105: public function isChildCalculated($item = null)
106: {
107: if ($item) {
108: if ($item->getOrderItem()) {
109: $item = $item->getOrderItem();
110: }
111: if ($parentItem = $item->getParentItem()) {
112: if ($options = $parentItem->getProductOptions()) {
113: if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
114: return true;
115: } else {
116: return false;
117: }
118: }
119: } else {
120: if ($options = $item->getProductOptions()) {
121: if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
122: return false;
123: } else {
124: return true;
125: }
126: }
127: }
128: }
129:
130: if ($options = $this->getOrderItem()->getProductOptions()) {
131: if (isset($options['product_calculations'])
132: && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
133: return true;
134: }
135: }
136: return false;
137: }
138:
139: public function getSelectionAttributes($item) {
140: if ($item instanceof Mage_Sales_Model_Order_Item) {
141: $options = $item->getProductOptions();
142: } else {
143: $options = $item->getOrderItem()->getProductOptions();
144: }
145: if (isset($options['bundle_selection_attributes'])) {
146: return unserialize($options['bundle_selection_attributes']);
147: }
148: return null;
149: }
150:
151: public function getOrderOptions($item = null)
152: {
153: $result = array();
154:
155: if ($options = $this->getOrderItem()->getProductOptions()) {
156: if (isset($options['options'])) {
157: $result = array_merge($result, $options['options']);
158: }
159: if (isset($options['additional_options'])) {
160: $result = array_merge($result, $options['additional_options']);
161: }
162: if (!empty($options['attributes_info'])) {
163: $result = array_merge($options['attributes_info'], $result);
164: }
165: }
166: return $result;
167: }
168:
169: public function getOrderItem()
170: {
171: if ($this->getItem() instanceof Mage_Sales_Order_Item) {
172: return $this->getItem();
173: } else {
174: return $this->getItem()->getOrderItem();
175: }
176: }
177:
178: public function getValueHtml($item)
179: {
180: $result = $this->htmlEscape($item->getName());
181: if (!$this->isShipmentSeparately($item)) {
182: if ($attributes = $this->getSelectionAttributes($item)) {
183: $result = sprintf('%d', $attributes['qty']) . ' x ' . $result;
184: }
185: }
186: if (!$this->isChildCalculated($item)) {
187: if ($attributes = $this->getSelectionAttributes($item)) {
188: $result .= " " . $this->getOrderItem()->getOrder()->formatPrice($attributes['price']);
189: }
190: }
191: return $result;
192: }
193:
194: public function canShowPriceInfo($item)
195: {
196: if (($item->getOrderItem()->getParentItem() && $this->isChildCalculated())
197: || (!$item->getOrderItem()->getParentItem() && !$this->isChildCalculated())) {
198: return true;
199: }
200: return false;
201: }
202: }
203: