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 abstract class Mage_Bundle_Model_Sales_Order_Pdf_Items_Abstract extends Mage_Sales_Model_Order_Pdf_Items_Abstract
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
00073
00074
00075
00076
00077
00078 public function isShipmentSeparately($item = null)
00079 {
00080 if ($item) {
00081 if ($item->getOrderItem()) {
00082 $item = $item->getOrderItem();
00083 }
00084 if ($parentItem = $item->getParentItem()) {
00085 if ($options = $parentItem->getProductOptions()) {
00086 if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00087 return true;
00088 } else {
00089 return false;
00090 }
00091 }
00092 } else {
00093 if ($options = $item->getProductOptions()) {
00094 if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00095 return false;
00096 } else {
00097 return true;
00098 }
00099 }
00100 }
00101 }
00102
00103 if ($options = $this->getOrderItem()->getProductOptions()) {
00104 if (isset($options['shipment_type']) && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00105 return true;
00106 }
00107 }
00108 return false;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 public function isChildCalculated($item = null)
00118 {
00119 if ($item) {
00120 if ($item->getOrderItem()) {
00121 $item = $item->getOrderItem();
00122 }
00123 if ($parentItem = $item->getParentItem()) {
00124 if ($options = $parentItem->getProductOptions()) {
00125 if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00126 return true;
00127 } else {
00128 return false;
00129 }
00130 }
00131 } else {
00132 if ($options = $item->getProductOptions()) {
00133 if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00134 return false;
00135 } else {
00136 return true;
00137 }
00138 }
00139 }
00140 }
00141
00142 if ($options = $this->getOrderItem()->getProductOptions()) {
00143 if (isset($options['product_calculations'])
00144 && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00145 return true;
00146 }
00147 }
00148 return false;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 public function getBundleOptions($item = null)
00158 {
00159 if ($options = $this->getOrderItem()->getProductOptions()) {
00160 if (isset($options['bundle_options'])) {
00161 return $options['bundle_options'];
00162 }
00163 }
00164 return array();
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 public function getSelectionAttributes($item)
00174 {
00175 if ($item instanceof Mage_Sales_Model_Order_Item) {
00176 $options = $item->getProductOptions();
00177 } else {
00178 $options = $item->getOrderItem()->getProductOptions();
00179 }
00180 if (isset($options['bundle_selection_attributes'])) {
00181 return unserialize($options['bundle_selection_attributes']);
00182 }
00183 return null;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192 public function getOrderOptions($item = null)
00193 {
00194 $result = array();
00195
00196 if ($options = $this->getOrderItem()->getProductOptions()) {
00197 if (isset($options['options'])) {
00198 $result = array_merge($result, $options['options']);
00199 }
00200 if (isset($options['additional_options'])) {
00201 $result = array_merge($result, $options['additional_options']);
00202 }
00203 if (!empty($options['attributes_info'])) {
00204 $result = array_merge($options['attributes_info'], $result);
00205 }
00206 }
00207 return $result;
00208 }
00209
00210
00211
00212
00213
00214
00215 public function getOrderItem()
00216 {
00217 if ($this->getItem() instanceof Mage_Sales_Order_Item) {
00218 return $this->getItem();
00219 } else {
00220 return $this->getItem()->getOrderItem();
00221 }
00222 }
00223
00224
00225
00226
00227
00228
00229
00230 public function getValueHtml($item)
00231 {
00232 $result = strip_tags($item->getName());
00233 if (!$this->isShipmentSeparately($item)) {
00234 if ($attributes = $this->getSelectionAttributes($item)) {
00235 $result = sprintf('%d', $attributes['qty']) . ' x ' . $result;
00236 }
00237 }
00238 if (!$this->isChildCalculated($item)) {
00239 if ($attributes = $this->getSelectionAttributes($item)) {
00240 $result .= " " . strip_tags($this->getOrderItem()->getOrder()->formatPrice($attributes['price']));
00241 }
00242 }
00243 return $result;
00244 }
00245
00246
00247
00248
00249
00250
00251
00252 public function canShowPriceInfo($item)
00253 {
00254 if (($item->getOrderItem()->getParentItem() && $this->isChildCalculated())
00255 || (!$item->getOrderItem()->getParentItem() && !$this->isChildCalculated())) {
00256 return true;
00257 }
00258 return false;
00259 }
00260 }