function basic_cart_payment_form_order_node_form_alter in Basic cart 7.3
Implementes hook_form_FORM_ID_alter().
File
- basic_cart_payment/
basic_cart_payment.module, line 6
Code
function basic_cart_payment_form_order_node_form_alter(&$form, &$form_state, $form_id) {
/**
* See https://www.drupal.org/node/921398
* Because of the way the node/form is created, we have this bug.
*/
form_load_include($form_state, 'inc', 'node', 'node.pages');
$pmids = payment_method_options();
if (isset($form_state['values']['basic_cart_payment_methods'])) {
$pmid = $form_state['values']['basic_cart_payment_methods'];
}
else {
foreach ($pmids as $key => $value) {
$pmid = $key;
break;
}
}
$form['basic_cart_payment_methods'] = array(
'#type' => 'radios',
'#title' => t('Available payment method'),
'#default_value' => $pmid,
'#options' => $pmids,
'#weight' => 50,
'#ajax' => array(
'callback' => 'basic_cart_payment_payment_form_generate',
'wrapper' => 'basic-cart-payment-options',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['payment'] = array(
'#title' => t("Payment options"),
'#prefix' => '<div id="basic-cart-payment-options">',
'#suffix' => '</div>',
'#type' => 'fieldset',
'#weight' => 51,
);
$payment_method = entity_load_single('payment_method', $pmid);
$currency = variable_get('basic_cart_currency');
$payment = new Payment(array(
'context' => 'basic_cart_payment',
'context_data' => array(
'destination' => $_GET['q'],
),
'currency_code' => $currency,
'description' => $payment_method->title_specific,
'finish_callback' => 'basic_cart_payment_finish',
'method' => $payment_method,
));
// Getting the cart.
$cart = basic_cart_get_cart();
if (!empty($cart) && is_array($cart)) {
foreach ($cart as $i => $item) {
$payment
->setLineItem(new PaymentLineItem(array(
'amount' => $item->basic_cart_unit_price,
'description' => $item->title,
'name' => $item->title,
'quantity' => $item->basic_cart_quantity,
)));
}
}
$form_info = payment_form_embedded($form_state, $payment, array(
$pmid,
));
unset($form_info['elements']['payment_status']);
$form['payment']['pay'] = $form_info['elements'];
return $form;
}