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