PickupItemRenderer.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Pickup\Pdf;
  6. use Magento\Framework\Data\Collection\AbstractDb;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Filesystem;
  9. use Magento\Framework\Filter\FilterManager;
  10. use Magento\Framework\Model\Context;
  11. use Magento\Framework\Model\ResourceModel\AbstractResource;
  12. use Magento\Framework\Registry;
  13. use Magento\Framework\Stdlib\StringUtils;
  14. use Magento\Sales\Model\Order\Pdf\Items\AbstractItems;
  15. use Magento\Tax\Helper\Data;
  16. /**
  17. * Temando Pickup Order Pdf default items renderer
  18. *
  19. * @package Temando\Shipping\Model
  20. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  21. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  22. * @link http://www.temando.com/
  23. */
  24. class PickupItemRenderer extends AbstractItems
  25. {
  26. /**
  27. * Core string
  28. *
  29. * @var StringUtils
  30. */
  31. private $string;
  32. /**
  33. * @param Context $context
  34. * @param Registry $registry
  35. * @param Data $taxData
  36. * @param Filesystem $filesystem
  37. * @param FilterManager $filterManager
  38. * @param StringUtils $string
  39. * @param AbstractResource $resource
  40. * @param AbstractDb $resourceCollection
  41. * @param array $data
  42. */
  43. public function __construct(
  44. Context $context,
  45. Registry $registry,
  46. Data $taxData,
  47. Filesystem $filesystem,
  48. FilterManager $filterManager,
  49. StringUtils $string,
  50. AbstractResource $resource = null,
  51. AbstractDb $resourceCollection = null,
  52. array $data = []
  53. ) {
  54. $this->string = $string;
  55. parent::__construct(
  56. $context,
  57. $registry,
  58. $taxData,
  59. $filesystem,
  60. $filterManager,
  61. $resource,
  62. $resourceCollection,
  63. $data
  64. );
  65. }
  66. /**
  67. * Draw item line
  68. *
  69. * @return void
  70. * @throws LocalizedException
  71. */
  72. public function draw()
  73. {
  74. $item = $this->getItem();
  75. $pdf = $this->getPdf();
  76. $page = $this->getPage();
  77. $lines = [];
  78. // draw Product name
  79. $lines[0] = [['text' => $this->string->split($item->getData('name'), 60, true, true), 'feed' => 100]];
  80. // draw QTY
  81. $lines[0][] = ['text' => $item->getData('qty') * 1, 'feed' => 35];
  82. // draw SKU
  83. $lines[0][] = [
  84. 'text' => $this->string->split($this->getSku($item), 25),
  85. 'feed' => 565,
  86. 'align' => 'right',
  87. ];
  88. // Custom options
  89. $options = $this->getItemOptions();
  90. if ($options) {
  91. foreach ($options as $option) {
  92. // draw options label
  93. $lines[][] = [
  94. 'text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true),
  95. 'font' => 'italic',
  96. 'feed' => 110,
  97. ];
  98. // draw options value
  99. if ($option['value']) {
  100. $printValue = isset(
  101. $option['print_value']
  102. ) ? $option['print_value'] : $this->filterManager->stripTags(
  103. $option['value']
  104. );
  105. $values = explode(', ', $printValue);
  106. foreach ($values as $value) {
  107. $lines[][] = ['text' => $this->string->split($value, 50, true, true), 'feed' => 115];
  108. }
  109. }
  110. }
  111. }
  112. $lineBlock = ['lines' => $lines, 'height' => 20];
  113. $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
  114. $this->setPage($page);
  115. }
  116. }