123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- /**
- * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
- */
- namespace Temando\Shipping\Model\Pickup\Pdf;
- use Magento\Framework\Data\Collection\AbstractDb;
- use Magento\Framework\Exception\LocalizedException;
- use Magento\Framework\Filesystem;
- use Magento\Framework\Filter\FilterManager;
- use Magento\Framework\Model\Context;
- use Magento\Framework\Model\ResourceModel\AbstractResource;
- use Magento\Framework\Registry;
- use Magento\Framework\Stdlib\StringUtils;
- use Magento\Sales\Model\Order\Pdf\Items\AbstractItems;
- use Magento\Tax\Helper\Data;
- /**
- * Temando Pickup Order Pdf default items renderer
- *
- * @package Temando\Shipping\Model
- * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * @link http://www.temando.com/
- */
- class PickupItemRenderer extends AbstractItems
- {
- /**
- * Core string
- *
- * @var StringUtils
- */
- private $string;
- /**
- * @param Context $context
- * @param Registry $registry
- * @param Data $taxData
- * @param Filesystem $filesystem
- * @param FilterManager $filterManager
- * @param StringUtils $string
- * @param AbstractResource $resource
- * @param AbstractDb $resourceCollection
- * @param array $data
- */
- public function __construct(
- Context $context,
- Registry $registry,
- Data $taxData,
- Filesystem $filesystem,
- FilterManager $filterManager,
- StringUtils $string,
- AbstractResource $resource = null,
- AbstractDb $resourceCollection = null,
- array $data = []
- ) {
- $this->string = $string;
- parent::__construct(
- $context,
- $registry,
- $taxData,
- $filesystem,
- $filterManager,
- $resource,
- $resourceCollection,
- $data
- );
- }
- /**
- * Draw item line
- *
- * @return void
- * @throws LocalizedException
- */
- public function draw()
- {
- $item = $this->getItem();
- $pdf = $this->getPdf();
- $page = $this->getPage();
- $lines = [];
- // draw Product name
- $lines[0] = [['text' => $this->string->split($item->getData('name'), 60, true, true), 'feed' => 100]];
- // draw QTY
- $lines[0][] = ['text' => $item->getData('qty') * 1, 'feed' => 35];
- // draw SKU
- $lines[0][] = [
- 'text' => $this->string->split($this->getSku($item), 25),
- 'feed' => 565,
- 'align' => 'right',
- ];
- // Custom options
- $options = $this->getItemOptions();
- if ($options) {
- foreach ($options as $option) {
- // draw options label
- $lines[][] = [
- 'text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true),
- 'font' => 'italic',
- 'feed' => 110,
- ];
- // draw options value
- if ($option['value']) {
- $printValue = isset(
- $option['print_value']
- ) ? $option['print_value'] : $this->filterManager->stripTags(
- $option['value']
- );
- $values = explode(', ', $printValue);
- foreach ($values as $value) {
- $lines[][] = ['text' => $this->string->split($value, 50, true, true), 'feed' => 115];
- }
- }
- }
- }
- $lineBlock = ['lines' => $lines, 'height' => 20];
- $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
- $this->setPage($page);
- }
- }
|