function uc_product_kit_buy_it_now_form_submit in Ubercart 8.4
Same name and namespace in other branches
- 5 uc_product_kit/uc_product_kit.module \uc_product_kit_buy_it_now_form_submit()
- 6.2 uc_product_kit/uc_product_kit.module \uc_product_kit_buy_it_now_form_submit()
- 7.3 uc_product_kit/uc_product_kit.module \uc_product_kit_buy_it_now_form_submit()
Form submission handler for uc_product_kit_buy_it_now_form().
See also
uc_product_kit_buy_it_now_form()
1 string reference to 'uc_product_kit_buy_it_now_form_submit'
- uc_product_kit_uc_form_alter in uc_product_kit/
uc_product_kit.module - Implements hook_uc_form_alter().
File
- uc_product_kit/
uc_product_kit.module, line 773 - The product kit module for Ubercart.
Code
function uc_product_kit_buy_it_now_form_submit($form, FormStateInterface $form_state) {
$node = Node::load($form_state
->getValue('nid'));
if (\Drupal::moduleHandler()
->moduleExists('uc_attribute')) {
$attributes = uc_product_get_attributes($node->nid);
if (!empty($attributes)) {
\Drupal::messenger()
->addError(t('This product has options that need to be selected before purchase. Please select them in the form below.'));
$form_state
->setRedirect('entity.node.canonical', [
'node' => $form_state
->getValue('nid'),
]);
return;
}
if (is_array($node->products)) {
foreach ($node->products as $nid => $product) {
$attributes = uc_product_get_attributes($nid);
if (!empty($attributes)) {
\Drupal::messenger()
->addError(t('This product has options that need to be selected before purchase. Please select them in the form below.'));
$form_state
->setRedirect('entity.node.canonical', [
'node' => $form_state
->getValue('nid'),
]);
return;
}
}
}
}
$msg = \Drupal::config('uc_cart.settings')
->get('add_item_msg');
$cart = \Drupal::service('uc_cart.manager')
->get();
$redirect = $cart
->addItem($form_state
->getValue('nid'), 1, $form_state
->getValues(), $msg);
if (isset($redirect)) {
$form_state
->setRedirectUrl($redirect);
}
}