You are here

protected function CheckoutFlowBase::onStepChange in Commerce Core 8.2

Reacts to the current step changing.

Called before saving the order and redirecting.

Handles the following logic 1) Locks the order before the payment page, 2) Unlocks the order when leaving the payment page 3) Places the order before the complete page.

Parameters

string $step_id: The new step ID.

2 calls to CheckoutFlowBase::onStepChange()
CheckoutFlowBase::redirectToStep in modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php
Redirects an order to a specific step in the checkout.
CheckoutFlowBase::submitForm in modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php
Form submission handler.

File

modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php, line 417

Class

CheckoutFlowBase
Provides the base checkout flow class.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

protected function onStepChange($step_id) {

  // Lock the order while on the 'payment' checkout step. Unlock elsewhere.
  if ($step_id == 'payment') {
    $this->order
      ->lock();
  }
  elseif ($step_id != 'payment') {
    $this->order
      ->unlock();
  }

  // Place the order.
  if ($step_id == 'complete' && $this->order
    ->getState()
    ->getId() == 'draft') {

    // Notify other modules.
    $event = new OrderEvent($this->order);
    $this->eventDispatcher
      ->dispatch(CheckoutEvents::COMPLETION, $event);
    $this->order
      ->getState()
      ->applyTransitionById('place');
  }
}