Create.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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;
  7. /**
  8. * Adminhtml sales order create
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class Create extends \Magento\Backend\Block\Widget\Form\Container
  15. {
  16. /**
  17. * Session quote
  18. *
  19. * @var \Magento\Backend\Model\Session\Quote
  20. */
  21. protected $_sessionQuote;
  22. /**
  23. * @param \Magento\Backend\Block\Widget\Context $context
  24. * @param \Magento\Backend\Model\Session\Quote $sessionQuote
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Backend\Block\Widget\Context $context,
  29. \Magento\Backend\Model\Session\Quote $sessionQuote,
  30. array $data = []
  31. ) {
  32. $this->_sessionQuote = $sessionQuote;
  33. parent::__construct($context, $data);
  34. }
  35. /**
  36. * Constructor
  37. *
  38. * @return void
  39. */
  40. protected function _construct()
  41. {
  42. $this->_objectId = 'order_id';
  43. $this->_controller = 'order';
  44. $this->_mode = 'create';
  45. parent::_construct();
  46. $this->setId('sales_order_create');
  47. $customerId = $this->_sessionQuote->getCustomerId();
  48. $storeId = $this->_sessionQuote->getStoreId();
  49. $this->buttonList->update('save', 'label', __('Submit Order'));
  50. $this->buttonList->update('save', 'onclick', 'order.submit()');
  51. $this->buttonList->update('save', 'class', 'primary');
  52. // Temporary solution, unset button widget. Will have to wait till jQuery migration is complete
  53. $this->buttonList->update('save', 'data_attribute', []);
  54. $this->buttonList->update('save', 'id', 'submit_order_top_button');
  55. if ($customerId === null || !$storeId) {
  56. $this->buttonList->update('save', 'style', 'display:none');
  57. }
  58. $this->buttonList->update('back', 'id', 'back_order_top_button');
  59. $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getBackUrl() . '\')');
  60. $this->buttonList->update('reset', 'id', 'reset_order_top_button');
  61. if ($customerId === null) {
  62. $this->buttonList->update('reset', 'style', 'display:none');
  63. } else {
  64. $this->buttonList->update('back', 'style', 'display:none');
  65. }
  66. $confirm = __('Are you sure you want to cancel this order?');
  67. $this->buttonList->update('reset', 'label', __('Cancel'));
  68. $this->buttonList->update('reset', 'class', 'cancel');
  69. $this->buttonList->update(
  70. 'reset',
  71. 'onclick',
  72. 'deleteConfirm(\'' . $confirm . '\', \'' . $this->getCancelUrl() . '\')'
  73. );
  74. }
  75. /**
  76. * {@inheritdoc}
  77. *
  78. * @return $this
  79. */
  80. protected function _prepareLayout()
  81. {
  82. $pageTitle = $this->getLayout()->createBlock(
  83. \Magento\Sales\Block\Adminhtml\Order\Create\Header::class
  84. )->toHtml();
  85. if (is_object($this->getLayout()->getBlock('page.title'))) {
  86. $this->getLayout()->getBlock('page.title')->setPageTitle($pageTitle);
  87. }
  88. return parent::_prepareLayout();
  89. }
  90. /**
  91. * Prepare header html
  92. *
  93. * @return string
  94. */
  95. public function getHeaderHtml()
  96. {
  97. $out = '<div id="order-header">' . $this->getLayout()->createBlock(
  98. \Magento\Sales\Block\Adminhtml\Order\Create\Header::class
  99. )->toHtml() . '</div>';
  100. return $out;
  101. }
  102. /**
  103. * Get header width
  104. *
  105. * @return string
  106. */
  107. public function getHeaderWidth()
  108. {
  109. return 'width: 70%;';
  110. }
  111. /**
  112. * Retrieve quote session object
  113. *
  114. * @return \Magento\Backend\Model\Session\Quote
  115. */
  116. protected function _getSession()
  117. {
  118. return $this->_sessionQuote;
  119. }
  120. /**
  121. * Get cancel url
  122. *
  123. * @return string
  124. */
  125. public function getCancelUrl()
  126. {
  127. if ($this->_sessionQuote->getOrder()->getId()) {
  128. $url = $this->getUrl('sales/order/view', ['order_id' => $this->_sessionQuote->getOrder()->getId()]);
  129. } else {
  130. $url = $this->getUrl('sales/*/cancel');
  131. }
  132. return $url;
  133. }
  134. /**
  135. * Get URL for back (reset) button
  136. *
  137. * @return string
  138. */
  139. public function getBackUrl()
  140. {
  141. return $this->getUrl('sales/' . $this->_controller . '/');
  142. }
  143. }