/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php

https://bitbucket.org/dnejedly/eaparts · PHP · 281 lines · 180 code · 17 blank · 84 comment · 63 complexity · 25f8fea2f3a39c1fa320cbf411d6de26 MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Bundle
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Sales Order Pdf Items renderer
  28. *
  29. * @category Mage
  30. * @package Mage_Bundle
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. abstract class Mage_Bundle_Model_Sales_Order_Pdf_Items_Abstract extends Mage_Sales_Model_Order_Pdf_Items_Abstract
  34. {
  35. /**
  36. * Getting all available childs for Invoice, Shipmen or Creditmemo item
  37. *
  38. * @param Varien_Object $item
  39. * @return array
  40. */
  41. public function getChilds($item)
  42. {
  43. $_itemsArray = array();
  44. if ($item instanceof Mage_Sales_Model_Order_Invoice_Item) {
  45. $_items = $item->getInvoice()->getAllItems();
  46. } else if ($item instanceof Mage_Sales_Model_Order_Shipment_Item) {
  47. $_items = $item->getShipment()->getAllItems();
  48. } else if ($item instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
  49. $_items = $item->getCreditmemo()->getAllItems();
  50. }
  51. if ($_items) {
  52. foreach ($_items as $_item) {
  53. $parentItem = $_item->getOrderItem()->getParentItem();
  54. if ($parentItem) {
  55. $_itemsArray[$parentItem->getId()][$_item->getOrderItemId()] = $_item;
  56. } else {
  57. $_itemsArray[$_item->getOrderItem()->getId()][$_item->getOrderItemId()] = $_item;
  58. }
  59. }
  60. }
  61. if (isset($_itemsArray[$item->getOrderItem()->getId()])) {
  62. return $_itemsArray[$item->getOrderItem()->getId()];
  63. } else {
  64. return null;
  65. }
  66. }
  67. /**
  68. * Retrieve is Shipment Separately flag for Item
  69. *
  70. * @param Varien_Object $item
  71. * @return bool
  72. */
  73. public function isShipmentSeparately($item = null)
  74. {
  75. if ($item) {
  76. if ($item->getOrderItem()) {
  77. $item = $item->getOrderItem();
  78. }
  79. $parentItem = $item->getParentItem();
  80. if ($parentItem) {
  81. $options = $parentItem->getProductOptions();
  82. if ($options) {
  83. if (isset($options['shipment_type'])
  84. && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
  85. return true;
  86. } else {
  87. return false;
  88. }
  89. }
  90. } else {
  91. $options = $item->getProductOptions();
  92. if ($options) {
  93. if (isset($options['shipment_type'])
  94. && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
  95. return false;
  96. } else {
  97. return true;
  98. }
  99. }
  100. }
  101. }
  102. $options = $this->getOrderItem()->getProductOptions();
  103. if ($options) {
  104. if (isset($options['shipment_type'])
  105. && $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
  106. return true;
  107. }
  108. }
  109. return false;
  110. }
  111. /**
  112. * Retrieve is Child Calculated
  113. *
  114. * @param Varien_Object $item
  115. * @return bool
  116. */
  117. public function isChildCalculated($item = null)
  118. {
  119. if ($item) {
  120. if ($item->getOrderItem()) {
  121. $item = $item->getOrderItem();
  122. }
  123. $parentItem = $item->getParentItem();
  124. if ($parentItem) {
  125. $options = $parentItem->getProductOptions();
  126. if ($options) {
  127. if (isset($options['product_calculations']) &&
  128. $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD
  129. ) {
  130. return true;
  131. } else {
  132. return false;
  133. }
  134. }
  135. } else {
  136. $options = $item->getProductOptions();
  137. if ($options) {
  138. if (isset($options['product_calculations']) &&
  139. $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD
  140. ) {
  141. return false;
  142. } else {
  143. return true;
  144. }
  145. }
  146. }
  147. }
  148. $options = $this->getOrderItem()->getProductOptions();
  149. if ($options) {
  150. if (isset($options['product_calculations'])
  151. && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
  152. return true;
  153. }
  154. }
  155. return false;
  156. }
  157. /**
  158. * Retrieve Bundle Options
  159. *
  160. * @param Varien_Object $item
  161. * @return array
  162. */
  163. public function getBundleOptions($item = null)
  164. {
  165. $options = $this->getOrderItem()->getProductOptions();
  166. if ($options) {
  167. if (isset($options['bundle_options'])) {
  168. return $options['bundle_options'];
  169. }
  170. }
  171. return array();
  172. }
  173. /**
  174. * Retrieve Selection attributes
  175. *
  176. * @param Varien_Object $item
  177. * @return mixed
  178. */
  179. public function getSelectionAttributes($item)
  180. {
  181. if ($item instanceof Mage_Sales_Model_Order_Item) {
  182. $options = $item->getProductOptions();
  183. } else {
  184. $options = $item->getOrderItem()->getProductOptions();
  185. }
  186. if (isset($options['bundle_selection_attributes'])) {
  187. return unserialize($options['bundle_selection_attributes']);
  188. }
  189. return null;
  190. }
  191. /**
  192. * Retrieve Order options
  193. *
  194. * @param Varien_Object $item
  195. * @return array
  196. */
  197. public function getOrderOptions($item = null)
  198. {
  199. $result = array();
  200. $options = $this->getOrderItem()->getProductOptions();
  201. if ($options) {
  202. if (isset($options['options'])) {
  203. $result = array_merge($result, $options['options']);
  204. }
  205. if (isset($options['additional_options'])) {
  206. $result = array_merge($result, $options['additional_options']);
  207. }
  208. if (!empty($options['attributes_info'])) {
  209. $result = array_merge($options['attributes_info'], $result);
  210. }
  211. }
  212. return $result;
  213. }
  214. /**
  215. * Retrieve Order Item
  216. *
  217. * @return Mage_Sales_Order_Item
  218. */
  219. public function getOrderItem()
  220. {
  221. if ($this->getItem() instanceof Mage_Sales_Order_Item) {
  222. return $this->getItem();
  223. } else {
  224. return $this->getItem()->getOrderItem();
  225. }
  226. }
  227. /**
  228. * Retrieve Value HTML
  229. *
  230. * @param Mage_Sales_Order_Item $item
  231. * @return string
  232. */
  233. public function getValueHtml($item)
  234. {
  235. $result = strip_tags($item->getName());
  236. if (!$this->isShipmentSeparately($item)) {
  237. $attributes = $this->getSelectionAttributes($item);
  238. if ($attributes) {
  239. $result = sprintf('%d', $attributes['qty']) . ' x ' . $result;
  240. }
  241. }
  242. if (!$this->isChildCalculated($item)) {
  243. $attributes = $this->getSelectionAttributes($item);
  244. if ($attributes) {
  245. $result .= " " . strip_tags($this->getOrderItem()->getOrder()->formatPrice($attributes['price']));
  246. }
  247. }
  248. return $result;
  249. }
  250. /**
  251. * Can show price info for item
  252. *
  253. * @param Mage_Sales_Order_Item $item
  254. * @return bool
  255. */
  256. public function canShowPriceInfo($item)
  257. {
  258. if (($item->getOrderItem()->getParentItem() && $this->isChildCalculated())
  259. || (!$item->getOrderItem()->getParentItem() && !$this->isChildCalculated())) {
  260. return true;
  261. }
  262. return false;
  263. }
  264. }