DefaultShipment.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order\Pdf\Items\Shipment;
  7. /**
  8. * Sales Order Shipment Pdf default items renderer
  9. */
  10. class DefaultShipment extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems
  11. {
  12. /**
  13. * Core string
  14. *
  15. * @var \Magento\Framework\Stdlib\StringUtils
  16. */
  17. protected $string;
  18. /**
  19. * @param \Magento\Framework\Model\Context $context
  20. * @param \Magento\Framework\Registry $registry
  21. * @param \Magento\Tax\Helper\Data $taxData
  22. * @param \Magento\Framework\Filesystem $filesystem
  23. * @param \Magento\Framework\Filter\FilterManager $filterManager
  24. * @param \Magento\Framework\Stdlib\StringUtils $string
  25. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  26. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  27. * @param array $data
  28. */
  29. public function __construct(
  30. \Magento\Framework\Model\Context $context,
  31. \Magento\Framework\Registry $registry,
  32. \Magento\Tax\Helper\Data $taxData,
  33. \Magento\Framework\Filesystem $filesystem,
  34. \Magento\Framework\Filter\FilterManager $filterManager,
  35. \Magento\Framework\Stdlib\StringUtils $string,
  36. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  37. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  38. array $data = []
  39. ) {
  40. $this->string = $string;
  41. parent::__construct(
  42. $context,
  43. $registry,
  44. $taxData,
  45. $filesystem,
  46. $filterManager,
  47. $resource,
  48. $resourceCollection,
  49. $data
  50. );
  51. }
  52. /**
  53. * Draw item line
  54. *
  55. * @return void
  56. */
  57. public function draw()
  58. {
  59. $item = $this->getItem();
  60. $pdf = $this->getPdf();
  61. $page = $this->getPage();
  62. $lines = [];
  63. // draw Product name
  64. $lines[0] = [['text' => $this->string->split($item->getName(), 60, true, true), 'feed' => 100]];
  65. // draw QTY
  66. $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 35];
  67. // draw SKU
  68. $lines[0][] = [
  69. 'text' => $this->string->split($this->getSku($item), 25),
  70. 'feed' => 565,
  71. 'align' => 'right',
  72. ];
  73. // Custom options
  74. $options = $this->getItemOptions();
  75. if ($options) {
  76. foreach ($options as $option) {
  77. // draw options label
  78. $lines[][] = [
  79. 'text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true),
  80. 'font' => 'italic',
  81. 'feed' => 110,
  82. ];
  83. // draw options value
  84. if ($option['value'] !== null) {
  85. $printValue = isset(
  86. $option['print_value']
  87. ) ? $option['print_value'] : $this->filterManager->stripTags(
  88. $option['value']
  89. );
  90. $values = explode(', ', $printValue);
  91. foreach ($values as $value) {
  92. $lines[][] = ['text' => $this->string->split($value, 50, true, true), 'feed' => 115];
  93. }
  94. }
  95. }
  96. }
  97. $lineBlock = ['lines' => $lines, 'height' => 20];
  98. $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
  99. $this->setPage($page);
  100. }
  101. }