Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultShipment.php
Go to the documentation of this file.
1 <?php
7 
11 class DefaultShipment extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems
12 {
18  protected $string;
19 
31  public function __construct(
32  \Magento\Framework\Model\Context $context,
33  \Magento\Framework\Registry $registry,
34  \Magento\Tax\Helper\Data $taxData,
35  \Magento\Framework\Filesystem $filesystem,
36  \Magento\Framework\Filter\FilterManager $filterManager,
37  \Magento\Framework\Stdlib\StringUtils $string,
38  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
39  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
40  array $data = []
41  ) {
42  $this->string = $string;
43  parent::__construct(
44  $context,
45  $registry,
46  $taxData,
49  $resource,
50  $resourceCollection,
51  $data
52  );
53  }
54 
60  public function draw()
61  {
62  $item = $this->getItem();
63  $pdf = $this->getPdf();
64  $page = $this->getPage();
65  $lines = [];
66 
67  // draw Product name
68  $lines[0] = [['text' => $this->string->split($item->getName(), 60, true, true), 'feed' => 100]];
69 
70  // draw QTY
71  $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 35];
72 
73  // draw SKU
74  $lines[0][] = [
75  'text' => $this->string->split($this->getSku($item), 25),
76  'feed' => 565,
77  'align' => 'right',
78  ];
79 
80  // Custom options
81  $options = $this->getItemOptions();
82  if ($options) {
83  foreach ($options as $option) {
84  // draw options label
85  $lines[][] = [
86  'text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true),
87  'font' => 'italic',
88  'feed' => 110,
89  ];
90 
91  // draw options value
92  if ($option['value'] !== null) {
93  $printValue = isset(
94  $option['print_value']
95  ) ? $option['print_value'] : $this->filterManager->stripTags(
96  $option['value']
97  );
98  $values = explode(', ', $printValue);
99  foreach ($values as $value) {
100  $lines[][] = ['text' => $this->string->split($value, 50, true, true), 'feed' => 115];
101  }
102  }
103  }
104  }
105 
106  $lineBlock = ['lines' => $lines, 'height' => 20];
107 
108  $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
109  $this->setPage($page);
110  }
111 }
$values
Definition: options.phtml:88
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Tax\Helper\Data $taxData, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
$page
Definition: pages.php:8
$filesystem