00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Bundle_Block_Adminhtml_Sales_Order_Items_Renderer extends Mage_Adminhtml_Block_Sales_Items_Renderer_Default
00036 {
00037
00038
00039
00040
00041
00042
00043 public function getChilds($item)
00044 {
00045 $_itemsArray = array();
00046
00047 if ($item instanceof Mage_Sales_Model_Order_Invoice_Item) {
00048 $_items = $item->getInvoice()->getAllItems();
00049 } else if ($item instanceof Mage_Sales_Model_Order_Shipment_Item) {
00050 $_items = $item->getShipment()->getAllItems();
00051 } else if ($item instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
00052 $_items = $item->getCreditmemo()->getAllItems();
00053 }
00054
00055 if ($_items) {
00056 foreach ($_items as $_item) {
00057 if ($parentItem = $_item->getOrderItem()->getParentItem()) {
00058 $_itemsArray[$parentItem->getId()][$_item->getOrderItemId()] = $_item;
00059 } else {
00060 $_itemsArray[$_item->getOrderItem()->getId()][$_item->getOrderItemId()] = $_item;
00061 }
00062 }
00063 }
00064
00065 if (isset($_itemsArray[$item->getOrderItem()->getId()])) {
00066 return $_itemsArray[$item->getOrderItem()->getId()];
00067 } else {
00068 return null;
00069 }
00070 }
00071
00072 public function isShipmentSeparately($item = null)
00073 {
00074 if ($item) {
00075 if ($item->getOrderItem()) {
00076 $item = $item->getOrderItem();
00077 }
00078 if ($parentItem = $item->getParentItem()) {
00079 if ($options = $parentItem->getProductOptions()) {
00080 if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00081 return true;
00082 } else {
00083 return false;
00084 }
00085 }
00086 } else {
00087 if ($options = $item->getProductOptions()) {
00088 if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00089 return false;
00090 } else {
00091 return true;
00092 }
00093 }
00094 }
00095 }
00096
00097 if ($options = $this->getOrderItem()->getProductOptions()) {
00098 if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00099 return true;
00100 }
00101 }
00102 return false;
00103 }
00104
00105 public function isChildCalculated($item = null)
00106 {
00107 if ($item) {
00108 if ($item->getOrderItem()) {
00109 $item = $item->getOrderItem();
00110 }
00111 if ($parentItem = $item->getParentItem()) {
00112 if ($options = $parentItem->getProductOptions()) {
00113 if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00114 return true;
00115 } else {
00116 return false;
00117 }
00118 }
00119 } else {
00120 if ($options = $item->getProductOptions()) {
00121 if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00122 return false;
00123 } else {
00124 return true;
00125 }
00126 }
00127 }
00128 }
00129
00130 if ($options = $this->getOrderItem()->getProductOptions()) {
00131 if (isset($options['product_calculations'])
00132 && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00133 return true;
00134 }
00135 }
00136 return false;
00137 }
00138
00139 public function getSelectionAttributes($item) {
00140 if ($item instanceof Mage_Sales_Model_Order_Item) {
00141 $options = $item->getProductOptions();
00142 } else {
00143 $options = $item->getOrderItem()->getProductOptions();
00144 }
00145 if (isset($options['bundle_selection_attributes'])) {
00146 return unserialize($options['bundle_selection_attributes']);
00147 }
00148 return null;
00149 }
00150
00151 public function getOrderOptions($item = null)
00152 {
00153 $result = array();
00154
00155 if ($options = $this->getOrderItem()->getProductOptions()) {
00156 if (isset($options['options'])) {
00157 $result = array_merge($result, $options['options']);
00158 }
00159 if (isset($options['additional_options'])) {
00160 $result = array_merge($result, $options['additional_options']);
00161 }
00162 if (!empty($options['attributes_info'])) {
00163 $result = array_merge($options['attributes_info'], $result);
00164 }
00165 }
00166 return $result;
00167 }
00168
00169 public function getOrderItem()
00170 {
00171 if ($this->getItem() instanceof Mage_Sales_Order_Item) {
00172 return $this->getItem();
00173 } else {
00174 return $this->getItem()->getOrderItem();
00175 }
00176 }
00177
00178 public function getValueHtml($item)
00179 {
00180 $result = $this->htmlEscape($item->getName());
00181 if (!$this->isShipmentSeparately($item)) {
00182 if ($attributes = $this->getSelectionAttributes($item)) {
00183 $result = sprintf('%d', $attributes['qty']) . ' x ' . $result;
00184 }
00185 }
00186 if (!$this->isChildCalculated($item)) {
00187 if ($attributes = $this->getSelectionAttributes($item)) {
00188 $result .= " " . $this->getOrderItem()->getOrder()->formatPrice($attributes['price']);
00189 }
00190 }
00191 return $result;
00192 }
00193
00194 public function canShowPriceInfo($item)
00195 {
00196 if (($item->getOrderItem()->getParentItem() && $this->isChildCalculated())
00197 || (!$item->getOrderItem()->getParentItem() && !$this->isChildCalculated())) {
00198 return true;
00199 }
00200 return false;
00201 }
00202 }