Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
State.php
Go to the documentation of this file.
1 <?php
7 
10 
17 {
18  const STEP_SELECT_ADDRESSES = 'multishipping_addresses';
19 
20  const STEP_SHIPPING = 'multishipping_shipping';
21 
22  const STEP_BILLING = 'multishipping_billing';
23 
24  const STEP_OVERVIEW = 'multishipping_overview';
25 
26  const STEP_SUCCESS = 'multishipping_success';
27 
28  const STEP_RESULTS = 'multishipping_results';
29 
35  protected $_steps;
36 
42  protected $_multishipping;
43 
47  protected $_checkoutSession;
48 
55  public function __construct(Session $checkoutSession, Multishipping $multishipping)
56  {
57  $this->_checkoutSession = $checkoutSession;
58  $this->_multishipping = $multishipping;
59  parent::__construct();
60  $this->_steps = [
61  self::STEP_SELECT_ADDRESSES => new \Magento\Framework\DataObject(['label' => __('Select Addresses')]),
62  self::STEP_SHIPPING => new \Magento\Framework\DataObject(['label' => __('Shipping Information')]),
63  self::STEP_BILLING => new \Magento\Framework\DataObject(['label' => __('Billing Information')]),
64  self::STEP_OVERVIEW => new \Magento\Framework\DataObject(['label' => __('Place Order')]),
65  self::STEP_SUCCESS => new \Magento\Framework\DataObject(['label' => __('Order Success')]),
66  self::STEP_RESULTS => new \Magento\Framework\DataObject(['label' => __('Order Results')]),
67  ];
68 
69  foreach ($this->_steps as $step) {
70  $step->setIsComplete(false);
71  }
72  $this->_steps[$this->getActiveStep()]->setIsActive(true);
73  }
74 
80  public function getCheckout()
81  {
82  return $this->_multishipping;
83  }
84 
90  public function getSteps()
91  {
92  return $this->_steps;
93  }
94 
100  public function getActiveStep()
101  {
102  $step = $this->getCheckoutSession()->getCheckoutState();
103  if (isset($this->_steps[$step])) {
104  return $step;
105  }
107  }
108 
113  public function setActiveStep($step)
114  {
115  if (isset($this->_steps[$step])) {
116  $this->getCheckoutSession()->setCheckoutState($step);
117  } else {
118  $this->getCheckoutSession()->setCheckoutState(self::STEP_SELECT_ADDRESSES);
119  }
120 
121  // Fix active step changing
122  if (!$this->_steps[$step]->getIsActive()) {
123  foreach ($this->getSteps() as $stepObject) {
124  $stepObject->unsIsActive();
125  }
126  $this->_steps[$step]->setIsActive(true);
127  }
128  return $this;
129  }
130 
137  public function setCompleteStep($step)
138  {
139  if (isset($this->_steps[$step])) {
140  $this->getCheckoutSession()->setStepData($step, 'is_complete', true);
141  }
142  return $this;
143  }
144 
152  public function getCompleteStep($step)
153  {
154  if (isset($this->_steps[$step])) {
155  return $this->getCheckoutSession()->getStepData($step, 'is_complete');
156  }
157  return false;
158  }
159 
166  public function unsCompleteStep($step)
167  {
168  if (isset($this->_steps[$step])) {
169  $this->getCheckoutSession()->setStepData($step, 'is_complete', false);
170  }
171  return $this;
172  }
173 
177  public function canSelectAddresses()
178  {
179  }
180 
184  public function canInputShipping()
185  {
186  }
187 
191  public function canSeeOverview()
192  {
193  }
194 
198  public function canSuccess()
199  {
200  }
201 
207  public function getCheckoutSession()
208  {
210  }
211 }
__()
Definition: __.php:13
__construct(Session $checkoutSession, Multishipping $multishipping)
Definition: State.php:55