Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions
AbstractItems Class Reference
Inheritance diagram for AbstractItems:
AbstractItems AbstractModel DataObject Creditmemo Invoice Shipment

Public Member Functions

 __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\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], Json $serializer=null)
 
 getChildren ($item)
 
 isShipmentSeparately ($item=null)
 
 isChildCalculated ($item=null)
 
 getBundleOptions ($item=null)
 
 getSelectionAttributes ($item)
 
 getOrderOptions ($item=null)
 
 getOrderItem ()
 
 getValueHtml ($item)
 
 canShowPriceInfo ($item)
 
- Public Member Functions inherited from AbstractItems
 __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\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 setOrder (\Magento\Sales\Model\Order $order)
 
 setSource (\Magento\Framework\Model\AbstractModel $source)
 
 setItem (\Magento\Framework\DataObject $item)
 
 setPdf (\Magento\Sales\Model\Order\Pdf\AbstractPdf $pdf)
 
 setPage (\Zend_Pdf_Page $page)
 
 getOrder ()
 
 getSource ()
 
 getItem ()
 
 getPdf ()
 
 getPage ()
 
 draw ()
 
 getItemPricesForDisplay ()
 
 getItemOptions ()
 
 getSku ($item)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractItems
 _formatOptionValue ($value)
 
 _setFontRegular ($size=7)
 
 _setFontBold ($size=7)
 
 _setFontItalic ($size=7)
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 
- Protected Attributes inherited from AbstractItems
 $_order
 
 $_source
 
 $_item
 
 $_pdf
 
 $_pdfPage
 
 $_taxData
 
 $_rootDirectory
 
 $filterManager
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Order pdf items renderer

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 17 of file AbstractItems.php.

Constructor & Destructor Documentation

◆ __construct()

__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\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
Json  $serializer = null 
)

Constructor

Parameters
\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\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data
\Magento\Framework\Serialize\Serializer\Json$serializer

Definition at line 39 of file AbstractItems.php.

49  {
50  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
51  parent::__construct(
52  $context,
53  $registry,
54  $taxData,
57  $resource,
58  $resourceCollection,
59  $data
60  );
61  }
$resource
Definition: bulk.php:12
$filesystem

Member Function Documentation

◆ canShowPriceInfo()

canShowPriceInfo (   $item)

Can show price info for item

Parameters
\Magento\Sales\Model\Order\Item$item
Returns
bool

Definition at line 282 of file AbstractItems.php.

283  {
284  if ($item->getOrderItem()->getParentItem() && $this->isChildCalculated() ||
285  !$item->getOrderItem()->getParentItem() && !$this->isChildCalculated()
286  ) {
287  return true;
288  }
289  return false;
290  }

◆ getBundleOptions()

getBundleOptions (   $item = null)

Retrieve Bundle Options

Parameters
\Magento\Framework\DataObject$item
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 184 of file AbstractItems.php.

185  {
186  $options = $this->getOrderItem()->getProductOptions();
187  if ($options && isset($options['bundle_options'])) {
188  return $options['bundle_options'];
189  }
190  return [];
191  }

◆ getChildren()

getChildren (   $item)

Getting all available children for Invoice, Shipment or CreditMemo item

Parameters
\Magento\Framework\DataObject$item
Returns
array

Definition at line 69 of file AbstractItems.php.

70  {
71  $itemsArray = [];
72 
73  $items = null;
74  if ($item instanceof \Magento\Sales\Model\Order\Invoice\Item) {
75  $items = $item->getInvoice()->getAllItems();
76  } elseif ($item instanceof \Magento\Sales\Model\Order\Shipment\Item) {
77  $items = $item->getShipment()->getAllItems();
78  } elseif ($item instanceof \Magento\Sales\Model\Order\Creditmemo\Item) {
79  $items = $item->getCreditmemo()->getAllItems();
80  }
81 
82  if ($items) {
83  foreach ($items as $value) {
84  $parentItem = $value->getOrderItem()->getParentItem();
85  if ($parentItem) {
86  $itemsArray[$parentItem->getId()][$value->getOrderItemId()] = $value;
87  } else {
88  $itemsArray[$value->getOrderItem()->getId()][$value->getOrderItemId()] = $value;
89  }
90  }
91  }
92 
93  if (isset($itemsArray[$item->getOrderItem()->getId()])) {
94  return $itemsArray[$item->getOrderItem()->getId()];
95  }
96  return null;
97  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16
$items

◆ getOrderItem()

getOrderItem ( )

Retrieve Order Item

Returns
\Magento\Sales\Model\Order\Item

Definition at line 242 of file AbstractItems.php.

243  {
244  if ($this->getItem() instanceof \Magento\Sales\Model\Order\Item) {
245  return $this->getItem();
246  }
247  return $this->getItem()->getOrderItem();
248  }

◆ getOrderOptions()

getOrderOptions (   $item = null)

Retrieve Order options

Parameters
\Magento\Framework\DataObject$item
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 219 of file AbstractItems.php.

220  {
221  $result = [];
222  $options = $this->getOrderItem()->getProductOptions();
223  if ($options) {
224  if (isset($options['options'])) {
225  $result = array_merge($result, $options['options']);
226  }
227  if (isset($options['additional_options'])) {
228  $result = array_merge($result, $options['additional_options']);
229  }
230  if (!empty($options['attributes_info'])) {
231  $result = array_merge($options['attributes_info'], $result);
232  }
233  }
234  return $result;
235  }

◆ getSelectionAttributes()

getSelectionAttributes (   $item)

Retrieve Selection attributes

Parameters
\Magento\Framework\DataObject$item
Returns
mixed

Definition at line 199 of file AbstractItems.php.

200  {
201  if ($item instanceof \Magento\Sales\Model\Order\Item) {
202  $options = $item->getProductOptions();
203  } else {
204  $options = $item->getOrderItem()->getProductOptions();
205  }
206  if (isset($options['bundle_selection_attributes'])) {
207  return $this->serializer->unserialize($options['bundle_selection_attributes']);
208  }
209  return null;
210  }

◆ getValueHtml()

getValueHtml (   $item)

Retrieve Value HTML

Parameters
\Magento\Sales\Model\Order\Item$item
Returns
string

Definition at line 256 of file AbstractItems.php.

257  {
258  $result = $this->filterManager->stripTags($item->getName());
259  if (!$this->isShipmentSeparately($item)) {
261  if ($attributes) {
262  $result = $this->filterManager->sprintf($attributes['qty'], ['format' => '%d']) . ' x ' . $result;
263  }
264  }
265  if (!$this->isChildCalculated($item)) {
267  if ($attributes) {
268  $result .= " " . $this->filterManager->stripTags(
269  $this->getOrderItem()->getOrder()->formatPrice($attributes['price'])
270  );
271  }
272  }
273  return $result;
274  }
$attributes
Definition: matrix.phtml:13

◆ isChildCalculated()

isChildCalculated (   $item = null)

Retrieve is Child Calculated

Parameters
\Magento\Framework\DataObject$item
Returns
bool @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 144 of file AbstractItems.php.

145  {
146  if ($item) {
147  if ($item->getOrderItem()) {
148  $item = $item->getOrderItem();
149  }
150  $parentItem = $item->getParentItem();
151  if ($parentItem) {
152  $options = $parentItem->getProductOptions();
153  if ($options) {
154  return (isset($options['product_calculations'])
155  && $options['product_calculations'] == AbstractType::CALCULATE_CHILD);
156  }
157  } else {
158  $options = $item->getProductOptions();
159  if ($options) {
160  return !(isset($options['product_calculations'])
161  && $options['product_calculations'] == AbstractType::CALCULATE_CHILD);
162  }
163  }
164  }
165 
166  $options = $this->getOrderItem()->getProductOptions();
167  if ($options) {
168  if (isset($options['product_calculations'])
169  && $options['product_calculations'] == AbstractType::CALCULATE_CHILD
170  ) {
171  return true;
172  }
173  }
174  return false;
175  }

◆ isShipmentSeparately()

isShipmentSeparately (   $item = null)

Retrieve is Shipment Separately flag for Item

Parameters
\Magento\Framework\DataObject$item
Returns
bool @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 106 of file AbstractItems.php.

107  {
108  if ($item) {
109  if ($item->getOrderItem()) {
110  $item = $item->getOrderItem();
111  }
112  $parentItem = $item->getParentItem();
113  if ($parentItem) {
114  $options = $parentItem->getProductOptions();
115  if ($options) {
116  return (isset($options['shipment_type'])
117  && $options['shipment_type'] == AbstractType::SHIPMENT_SEPARATELY);
118  }
119  } else {
120  $options = $item->getProductOptions();
121  if ($options) {
122  return !(isset($options['shipment_type'])
123  && $options['shipment_type'] == AbstractType::SHIPMENT_SEPARATELY);
124  }
125  }
126  }
127 
128  $options = $this->getOrderItem()->getProductOptions();
129  if ($options) {
130  if (isset($options['shipment_type']) && $options['shipment_type'] == AbstractType::SHIPMENT_SEPARATELY) {
131  return true;
132  }
133  }
134  return false;
135  }

The documentation for this class was generated from the following file: