You are here

public function CheckoutFlowBase::redirectToStep in Commerce Core 8.2

Redirects an order to a specific step in the checkout.

Parameters

string $step_id: The step ID to redirect to.

Throws

\Drupal\commerce\Response\NeedsRedirectException

Overrides CheckoutFlowInterface::redirectToStep

File

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

Class

CheckoutFlowBase
Provides the base checkout flow class.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

public function redirectToStep($step_id) {
  if (!$this
    ->isStepVisible($step_id)) {
    throw new \InvalidArgumentException(sprintf('Invalid step ID "%s" passed to redirectToStep().', $step_id));
  }
  $this->order
    ->set('checkout_step', $step_id);
  $this
    ->onStepChange($step_id);
  $this->order
    ->save();
  throw new NeedsRedirectException(Url::fromRoute('commerce_checkout.form', [
    'commerce_order' => $this->order
      ->id(),
    'step' => $step_id,
  ])
    ->toString());
}