/app/code/community/Vianetz/AdvancedInvoiceLayout/Model/Order/Pdf/Items/Bundle/Shipment.php

https://bitbucket.org/spenna/alexoo_produzione · PHP · 154 lines · 122 code · 20 blank · 12 comment · 21 complexity · 400c778b43a9cad947614fea77b62db0 MD5 · raw file

  1. <?php
  2. /**
  3. * AdvancedInvoiceLayout Shipment Bundle Pdf Items renderer
  4. *
  5. * @category Vianetz
  6. * @package Vianetz_AdvancedInvoiceLayout
  7. * @author Christoph Massmann <C.Massmann@vianetz.com>
  8. * @license http://www.vianetz.com/license
  9. */
  10. class Vianetz_AdvancedInvoiceLayout_Model_Order_Pdf_Items_Bundle_Shipment extends Vianetz_AdvancedInvoiceLayout_Model_Order_Pdf_Items_Bundle_Abstract
  11. {
  12. /**
  13. * Draw item line
  14. */
  15. public function draw()
  16. {
  17. $order = $this->getOrder();
  18. $item = $this->getItem();
  19. $pdf = $this->getPdf();
  20. $page = $this->getPage();
  21. $this->loadConfig($pdf, $order->getStore());
  22. $this->_setFontRegular();
  23. $shipItems = $this->getChilds($item);
  24. $items = array_merge(array($item->getOrderItem()), $item->getOrderItem()->getChildrenItems());
  25. $_prevOptionId = '';
  26. foreach ($items as $_item) {
  27. $shift = array(0, 10, 0);
  28. $attributes = $this->getSelectionAttributes($_item);
  29. if ($pdf->y-$shift[1] < $pdf->footer_y+30) {
  30. $pdf->page = $this->_newPage($pdf, $pdf->page, $order->getStore());
  31. }
  32. if ($_item->getParentItem()) {
  33. if ($_prevOptionId != $attributes['option_id']) {
  34. $this->_setFontItalic();
  35. foreach
  36. (Mage::helper('core/string')->str_split($attributes['option_label'],58-$this->fontsize_regular*2,
  37. true, true) as $key => $part) {
  38. $pdf->y -= 10;
  39. $pdf->page->drawText($part, $this->margin_left+108, $pdf->y,
  40. $this->charset);
  41. }
  42. $this->_setFontRegular();
  43. $_prevOptionId = $attributes['option_id'];
  44. $pdf->y -= 10;
  45. }
  46. }
  47. if (($this->isShipmentSeparately() && $_item->getParentItem()) || (!$this->isShipmentSeparately() && !$_item->getParentItem())) {
  48. if (isset($shipItems[$_item->getId()])) {
  49. $qty = $shipItems[$_item->getId()]->getQty()*1;
  50. } else if ($_item->getIsVirtual()) {
  51. $qty = Mage::helper('bundle')->__('N/A');
  52. } else {
  53. $qty = 0;
  54. }
  55. } else {
  56. $qty = '';
  57. }
  58. $pdf->page->drawText($qty, $page->getWidth()-$this->margin_right-130, $pdf->y,
  59. $this->charset);
  60. if ($_item->getParentItem()) {
  61. $feed = $this->margin_left+113;
  62. $name = $this->getValueHtml($_item);
  63. $shortdesc = $this->_parseItemShortDescription($_item);
  64. } else {
  65. $feed = $this->margin_left+108;
  66. $name = $_item->getName();
  67. $shortdesc = $this->_parseShortDescription();
  68. }
  69. foreach (Mage::helper('core/string')->str_split($name,
  70. 58-$this->fontsize_regular*2, true, true) as $key => $part) {
  71. $pdf->page->drawText($part, $feed, $pdf->y-$shift[0],
  72. $this->charset);
  73. $shift[0] += 10;
  74. }
  75. if (
  76. Mage::getStoreConfig(Vianetz_AdvancedInvoiceLayout_Model_Order_Pdf_Items_Abstract::XML_PATH_SALES_PDF_SHIPMENT_SHOW_PRODUCT_SHORTDESCRIPTION,
  77. $order->getStore()) ) {
  78. $shift[0] += 4;
  79. $this->_setFontRegular($this->fontsize_regular-1);
  80. foreach
  81. (Mage::helper('core/string')->str_split(strip_tags($shortdesc),
  82. 60-$this->fontsize_regular*2,
  83. true, true) as $description) {
  84. $shift[0] += 10;
  85. $pdf->page->drawText(strip_tags($description), $feed, $pdf->y-$shift[0],
  86. $this->charset);
  87. }
  88. $this->_setFontRegular();
  89. }
  90. foreach (Mage::helper('core/string')->str_split($item->getSku(), 15) as $key => $part) {
  91. if ($key > 0) {
  92. $shift[2] += 10;
  93. }
  94. $pdf->page->drawText($part, $this->margin_left+8, $pdf->y-$shift[2],
  95. $this->charset);
  96. }
  97. $pdf->y -=max($shift)+10;
  98. }
  99. if ($item->getOrderItem()->getProductOptions() || $item->getOrderItem()->getDescription()) {
  100. $shift[1] = 10;
  101. $options = $item->getOrderItem()->getProductOptions();
  102. if (isset($options['options'])) {
  103. foreach ($options['options'] as $option) {
  104. $this->_setFontItalic();
  105. foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false,true) as $_option) {
  106. $pdf->page->drawText($_option, $this->margin_left+108, $pdf->y-$shift[1],
  107. $this->charset);
  108. $shift[1] += 10;
  109. }
  110. $this->_setFontRegular();
  111. if ($option['value']) {
  112. $_printValue = isset($option['print_value']) ?
  113. $option['print_value'] : strip_tags($option['value']);
  114. $values = explode(', ', $_printValue);
  115. foreach ($values as $value) {
  116. foreach (Mage::helper('core/string')->str_split($value, 70,true,true) as $_value) {
  117. $pdf->page->drawText($_value, $this->margin_left+113, $pdf->y-$shift[1],
  118. $this->charset);
  119. $shift[1] += 10;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. foreach ($this->_parseDescription() as $description){
  126. $pdf->page->drawText(strip_tags($description), $this->margin_left+113, $pdf->y-$shift{1},
  127. $this->charset);
  128. $shift{1} += 10;
  129. }
  130. $pdf->y -= max($shift)+10;
  131. }
  132. }
  133. }
  134. /* vim: set ts=4 sw=4 expandtab nu tw=90: */