Items.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order\Create;
  7. use Magento\Quote\Model\Quote\Item;
  8. /**
  9. * Adminhtml sales order create items block
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Items extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
  16. {
  17. /**
  18. * Contains button descriptions to be shown at the top of accordion
  19. *
  20. * @var array
  21. */
  22. protected $_buttons = [];
  23. /**
  24. * Define block ID
  25. *
  26. * @return void
  27. */
  28. protected function _construct()
  29. {
  30. parent::_construct();
  31. $this->setId('sales_order_create_items');
  32. }
  33. /**
  34. * Accordion header text
  35. *
  36. * @return \Magento\Framework\Phrase
  37. */
  38. public function getHeaderText()
  39. {
  40. return __('Items Ordered');
  41. }
  42. /**
  43. * Returns all visible items
  44. *
  45. * @return Item[]
  46. */
  47. public function getItems()
  48. {
  49. return $this->getQuote()->getAllVisibleItems();
  50. }
  51. /**
  52. * Add button to the items header
  53. *
  54. * @param array $args
  55. * @return void
  56. */
  57. public function addButton($args)
  58. {
  59. $this->_buttons[] = $args;
  60. }
  61. /**
  62. * Render buttons and return HTML code
  63. *
  64. * @return string
  65. */
  66. public function getButtonsHtml()
  67. {
  68. $html = '';
  69. // Make buttons to be rendered in opposite order of addition. This makes "Add products" the last one.
  70. $this->_buttons = array_reverse($this->_buttons);
  71. foreach ($this->_buttons as $buttonData) {
  72. $html .= $this->getLayout()->createBlock(
  73. \Magento\Backend\Block\Widget\Button::class
  74. )->setData(
  75. $buttonData
  76. )->toHtml();
  77. }
  78. return $html;
  79. }
  80. /**
  81. * Return HTML code of the block
  82. *
  83. * @return string
  84. */
  85. protected function _toHtml()
  86. {
  87. if ($this->getStoreId()) {
  88. return parent::_toHtml();
  89. }
  90. return '';
  91. }
  92. }