Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Create.php
Go to the documentation of this file.
1 <?php
7 
15 class Create extends \Magento\Backend\Block\Widget\Form\Container
16 {
22  protected $_sessionQuote;
23 
29  public function __construct(
30  \Magento\Backend\Block\Widget\Context $context,
31  \Magento\Backend\Model\Session\Quote $sessionQuote,
32  array $data = []
33  ) {
34  $this->_sessionQuote = $sessionQuote;
35  parent::__construct($context, $data);
36  }
37 
43  protected function _construct()
44  {
45  $this->_objectId = 'order_id';
46  $this->_controller = 'order';
47  $this->_mode = 'create';
48 
49  parent::_construct();
50 
51  $this->setId('sales_order_create');
52 
53  $customerId = $this->_sessionQuote->getCustomerId();
54  $storeId = $this->_sessionQuote->getStoreId();
55 
56  $this->buttonList->update('save', 'label', __('Submit Order'));
57  $this->buttonList->update('save', 'onclick', 'order.submit()');
58  $this->buttonList->update('save', 'class', 'primary');
59  // Temporary solution, unset button widget. Will have to wait till jQuery migration is complete
60  $this->buttonList->update('save', 'data_attribute', []);
61 
62  $this->buttonList->update('save', 'id', 'submit_order_top_button');
63  if ($customerId === null || !$storeId) {
64  $this->buttonList->update('save', 'style', 'display:none');
65  }
66 
67  $this->buttonList->update('back', 'id', 'back_order_top_button');
68  $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getBackUrl() . '\')');
69 
70  $this->buttonList->update('reset', 'id', 'reset_order_top_button');
71 
72  if ($customerId === null) {
73  $this->buttonList->update('reset', 'style', 'display:none');
74  } else {
75  $this->buttonList->update('back', 'style', 'display:none');
76  }
77 
78  $confirm = __('Are you sure you want to cancel this order?');
79  $this->buttonList->update('reset', 'label', __('Cancel'));
80  $this->buttonList->update('reset', 'class', 'cancel');
81  $this->buttonList->update(
82  'reset',
83  'onclick',
84  'deleteConfirm(\'' . $confirm . '\', \'' . $this->getCancelUrl() . '\')'
85  );
86  }
87 
93  protected function _prepareLayout()
94  {
95  $pageTitle = $this->getLayout()->createBlock(
96  \Magento\Sales\Block\Adminhtml\Order\Create\Header::class
97  )->toHtml();
98  if (is_object($this->getLayout()->getBlock('page.title'))) {
99  $this->getLayout()->getBlock('page.title')->setPageTitle($pageTitle);
100  }
101  return parent::_prepareLayout();
102  }
103 
109  public function getHeaderHtml()
110  {
111  $out = '<div id="order-header">' . $this->getLayout()->createBlock(
112  \Magento\Sales\Block\Adminhtml\Order\Create\Header::class
113  )->toHtml() . '</div>';
114  return $out;
115  }
116 
122  public function getHeaderWidth()
123  {
124  return 'width: 70%;';
125  }
126 
132  protected function _getSession()
133  {
134  return $this->_sessionQuote;
135  }
136 
142  public function getCancelUrl()
143  {
144  if ($this->_sessionQuote->getOrder()->getId()) {
145  $url = $this->getUrl('sales/order/view', ['order_id' => $this->_sessionQuote->getOrder()->getId()]);
146  } else {
147  $url = $this->getUrl('sales/*/cancel');
148  }
149 
150  return $url;
151  }
152 
158  public function getBackUrl()
159  {
160  return $this->getUrl('sales/' . $this->_controller . '/');
161  }
162 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Backend\Model\Session\Quote $sessionQuote, array $data=[])
Definition: Create.php:29