You are here

public function CheckoutController::review in Ubercart 8.4

Allows a customer to review their order before finally submitting it.

1 string reference to 'CheckoutController::review'
uc_cart.routing.yml in uc_cart/uc_cart.routing.yml
uc_cart/uc_cart.routing.yml

File

uc_cart/src/Controller/CheckoutController.php, line 200

Class

CheckoutController
Controller routines for the checkout.

Namespace

Drupal\uc_cart\Controller

Code

public function review() {
  if (!$this->session
    ->has('cart_order') || !$this->session
    ->has('uc_checkout_review_' . $this->session
    ->get('cart_order'))) {
    return $this
      ->redirect('uc_cart.checkout');
  }
  $order = $this
    ->loadOrder();
  if (!$order || $order
    ->getStateId() != 'in_checkout') {
    $this->session
      ->remove('uc_checkout_complete_' . $this->session
      ->get('cart_order'));
    return $this
      ->redirect('uc_cart.checkout');
  }
  elseif (!uc_order_product_revive($order->products)) {
    $this
      ->messenger()
      ->addError($this
      ->t('Some of the products in this order are no longer available.'));
    return $this
      ->redirect('uc_cart.cart');
  }
  $filter = [
    'enabled' => FALSE,
  ];

  // If the cart isn't shippable, bypass panes with shippable == TRUE.
  if (!$order
    ->isShippable() && $this
    ->config('uc_cart.settings')
    ->get('panes.delivery.settings.delivery_not_shippable')) {
    $filter['shippable'] = TRUE;
  }
  $panes = $this->checkoutPaneManager
    ->getPanes($filter);
  foreach ($panes as $pane) {
    $return = $pane
      ->review($order);
    if (!is_null($return)) {
      $data[$pane
        ->getTitle()] = $return;
    }
  }
  $build = [
    '#theme' => 'uc_cart_checkout_review',
    '#panes' => $data,
    '#form' => $this
      ->formBuilder()
      ->getForm('Drupal\\uc_cart\\Form\\CheckoutReviewForm', $order),
  ];
  $build['#attached']['library'][] = 'uc_cart/uc_cart.styles';
  $build['#attached']['library'][] = 'uc_cart/uc_cart.review.scripts';

  // Invoke the customer reviews order checkout hook.
  $this
    ->moduleHandler()
    ->invokeAll('uc_cart_checkout_review_order', [
    $order,
  ]);

  // Trigger the checkout review order event.

  /* rules_invoke_event('uc_cart_checkout_review_order', $order); */
  $event = new CheckoutReviewOrderEvent($order);
  \Drupal::service('event_dispatcher')
    ->dispatch($event::EVENT_NAME, $event);
  return $build;
}