You are here

public function CartForm::submitForm in Basic cart 8.0

Same name and namespace in other branches
  1. 8.6 src/Form/CartForm.php \Drupal\basic_cart\Form\CartForm::submitForm()
  2. 8 src/Form/CartForm.php \Drupal\basic_cart\Form\CartForm::submitForm()
  3. 8.2 src/Form/CartForm.php \Drupal\basic_cart\Form\CartForm::submitForm()
  4. 8.3 src/Form/CartForm.php \Drupal\basic_cart\Form\CartForm::submitForm()
  5. 8.4 src/Form/CartForm.php \Drupal\basic_cart\Form\CartForm::submitForm()
  6. 8.5 src/Form/CartForm.php \Drupal\basic_cart\Form\CartForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/CartForm.php, line 83

Class

CartForm

Namespace

Drupal\basic_cart\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = Utility::cartSettings();
  if ($config
    ->get('quantity_status')) {
    foreach ($form_state
      ->getValue('cartcontents') as $nid => $value) {
      $quantity = (int) $value;
      if ($quantity > 0) {
        $_SESSION['basic_cart']['cart_quantity'][$nid] = $quantity;
      }
      elseif ($quantity == 0) {
        unset($_SESSION['basic_cart']['cart'][$nid]);
        unset($_SESSION['basic_cart']['cart_quantity'][$nid]);
      }
    }
    Utility::cartUpdatedMessage();
  }
  $config = Utility::cartSettings();
  if ($config
    ->get('order_status') && $form_state
    ->getValue('checkout')) {
    $url = new Url('basic_cart.checkout');
    $form_state
      ->setRedirectUrl($url);
  }
}