function uc_product_kit_buy_it_now_form_validate in Ubercart 8.4
Same name and namespace in other branches
- 6.2 uc_product_kit/uc_product_kit.module \uc_product_kit_buy_it_now_form_validate()
- 7.3 uc_product_kit/uc_product_kit.module \uc_product_kit_buy_it_now_form_validate()
Redirects to the product kit page so attributes may be selected.
See also
uc_product_kit_buy_it_now_form()
1 string reference to 'uc_product_kit_buy_it_now_form_validate'
- 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 753 - The product kit module for Ubercart.
Code
function uc_product_kit_buy_it_now_form_validate($form, FormStateInterface $form_state) {
if (\Drupal::moduleHandler()
->moduleExists('uc_attribute')) {
$node = Node::load($form_state
->getValue('nid'));
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.'));
return new RedirectResponse(Url::fromRoute('entity.node.canonical', [
'node' => $form_state
->getValue('nid'),
])
->toString());
}
}
}
}
}