DefaultItems.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Order\Email\Items;
  7. use Magento\Sales\Model\Order\Creditmemo\Item as CreditmemoItem;
  8. use Magento\Sales\Model\Order\Invoice\Item as InvoiceItem;
  9. use Magento\Sales\Model\Order\Item as OrderItem;
  10. /**
  11. * Sales Order Email items default renderer
  12. *
  13. * @api
  14. * @author Magento Core Team <core@magentocommerce.com>
  15. * @since 100.0.2
  16. */
  17. class DefaultItems extends \Magento\Framework\View\Element\Template
  18. {
  19. /**
  20. * Retrieve current order model instance
  21. *
  22. * @return \Magento\Sales\Model\Order
  23. */
  24. public function getOrder()
  25. {
  26. return $this->getItem()->getOrder();
  27. }
  28. /**
  29. * @return array
  30. */
  31. public function getItemOptions()
  32. {
  33. $result = [];
  34. if ($options = $this->getItem()->getOrderItem()->getProductOptions()) {
  35. if (isset($options['options'])) {
  36. $result = array_merge($result, $options['options']);
  37. }
  38. if (isset($options['additional_options'])) {
  39. $result = array_merge($result, $options['additional_options']);
  40. }
  41. if (isset($options['attributes_info'])) {
  42. $result = array_merge($result, $options['attributes_info']);
  43. }
  44. }
  45. return $result;
  46. }
  47. /**
  48. * @param string|array $value
  49. * @return string
  50. */
  51. public function getValueHtml($value)
  52. {
  53. if (is_array($value)) {
  54. return sprintf(
  55. '%d',
  56. $value['qty']
  57. ) . ' x ' . $this->escapeHtml(
  58. $value['title']
  59. ) . " " . $this->getItem()->getOrder()->formatPrice(
  60. $value['price']
  61. );
  62. } else {
  63. return $this->escapeHtml($value);
  64. }
  65. }
  66. /**
  67. * @param mixed $item
  68. * @return mixed
  69. */
  70. public function getSku($item)
  71. {
  72. if ($item->getOrderItem()->getProductOptionByCode('simple_sku')) {
  73. return $item->getOrderItem()->getProductOptionByCode('simple_sku');
  74. } else {
  75. return $item->getSku();
  76. }
  77. }
  78. /**
  79. * Return product additional information block
  80. *
  81. * @return \Magento\Framework\View\Element\AbstractBlock
  82. */
  83. public function getProductAdditionalInformationBlock()
  84. {
  85. return $this->getLayout()->getBlock('additional.product.info');
  86. }
  87. /**
  88. * Get the html for item price
  89. *
  90. * @param OrderItem|InvoiceItem|CreditmemoItem $item
  91. * @return string
  92. */
  93. public function getItemPrice($item)
  94. {
  95. $block = $this->getLayout()->getBlock('item_price');
  96. $block->setItem($item);
  97. return $block->toHtml();
  98. }
  99. }