123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Bundle\Model\Sales\Order\Pdf\Items;
- use Magento\Framework\App\ObjectManager;
- use Magento\Framework\Serialize\Serializer\Json;
- /**
- * Order shipment pdf items renderer
- */
- class Shipment extends AbstractItems
- {
- /**
- * @var \Magento\Framework\Stdlib\StringUtils
- */
- protected $string;
- /**
- * Constructor
- *
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Tax\Helper\Data $taxData
- * @param \Magento\Framework\Filesystem $filesystem
- * @param \Magento\Framework\Filter\FilterManager $filterManager
- * @param \Magento\Framework\Stdlib\StringUtils $string
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __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 = [],
- Json $serializer = null
- ) {
- $this->string = $string;
- parent::__construct(
- $context,
- $registry,
- $taxData,
- $filesystem,
- $filterManager,
- $resource,
- $resourceCollection,
- $data,
- $serializer
- );
- }
- /**
- * Draw item line
- *
- * @return void
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function draw()
- {
- $item = $this->getItem();
- $pdf = $this->getPdf();
- $page = $this->getPage();
- $this->_setFontRegular();
- $shipItems = $this->getChildren($item);
- $items = array_merge([$item->getOrderItem()], $item->getOrderItem()->getChildrenItems());
- $prevOptionId = '';
- $drawItems = [];
- foreach ($items as $childItem) {
- $line = [];
- $attributes = $this->getSelectionAttributes($childItem);
- if (is_array($attributes)) {
- $optionId = $attributes['option_id'];
- } else {
- $optionId = 0;
- }
- if (!isset($drawItems[$optionId])) {
- $drawItems[$optionId] = ['lines' => [], 'height' => 15];
- }
- if ($childItem->getParentItem()) {
- if ($prevOptionId != $attributes['option_id']) {
- $line[0] = [
- 'font' => 'italic',
- 'text' => $this->string->split($attributes['option_label'], 60, true, true),
- 'feed' => 60,
- ];
- $drawItems[$optionId] = ['lines' => [$line], 'height' => 15];
- $line = [];
- $prevOptionId = $attributes['option_id'];
- }
- }
- if ($this->isShipmentSeparately() && $childItem->getParentItem() ||
- !$this->isShipmentSeparately() && !$childItem->getParentItem()
- ) {
- if (isset($shipItems[$childItem->getId()])) {
- $qty = $shipItems[$childItem->getId()]->getQty() * 1;
- } elseif ($childItem->getIsVirtual()) {
- $qty = __('N/A');
- } else {
- $qty = 0;
- }
- } else {
- $qty = '';
- }
- $line[] = ['text' => $qty, 'feed' => 35];
- // draw Name
- if ($childItem->getParentItem()) {
- $feed = 65;
- $name = $this->getValueHtml($childItem);
- } else {
- $feed = 60;
- $name = $childItem->getName();
- }
- $text = [];
- foreach ($this->string->split($name, 60, true, true) as $part) {
- $text[] = $part;
- }
- $line[] = ['text' => $text, 'feed' => $feed];
- // draw SKUs
- $text = [];
- foreach ($this->string->split($childItem->getSku(), 25) as $part) {
- $text[] = $part;
- }
- $line[] = ['text' => $text, 'feed' => 440];
- $drawItems[$optionId]['lines'][] = $line;
- }
- // custom options
- $options = $item->getOrderItem()->getProductOptions();
- if ($options) {
- if (isset($options['options'])) {
- foreach ($options['options'] as $option) {
- $lines = [];
- $lines[][] = [
- 'text' => $this->string->split(
- $this->filterManager->stripTags($option['label']),
- 70,
- true,
- true
- ),
- 'font' => 'italic',
- 'feed' => 60,
- ];
- if ($option['value']) {
- $text = [];
- $printValue = isset(
- $option['print_value']
- ) ? $option['print_value'] : $this->filterManager->stripTags(
- $option['value']
- );
- $values = explode(', ', $printValue);
- foreach ($values as $value) {
- foreach ($this->string->split($value, 50, true, true) as $subValue) {
- $text[] = $subValue;
- }
- }
- $lines[][] = ['text' => $text, 'feed' => 65];
- }
- $drawItems[] = ['lines' => $lines, 'height' => 15];
- }
- }
- }
- $page = $pdf->drawLineBlocks($page, $drawItems, ['table_header' => true]);
- $this->setPage($page);
- }
- }
|