function commerce_gc_form_commerce_order_ui_order_form_alter in Commerce GC 7
File
- ./
commerce_gc.module, line 755 - Provides Giftcard coupon bundle, Giftcard Transaction entity and basic user interface elements.
Code
function commerce_gc_form_commerce_order_ui_order_form_alter(&$form, &$form_state) {
// Store the original total of each line item so that we can compute a delta
// when we write the transaction. Only do this once to capture just the line
// items that were previously saved in the db and thus have transactions
// written already.
$order = $form_state['commerce_order'];
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
if (!isset($form_state['original_gc_line_items'])) {
$form_state['original_gc_line_items'] = array();
foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
if ($line_item_wrapper
->value() && $line_item_wrapper->type
->value() == 'giftcard_use') {
$coupon_id = $line_item_wrapper->commerce_giftcard->coupon_id
->value();
if ($line_item_wrapper->type
->value() == 'giftcard_use') {
$form_state['original_gc_line_items'][$coupon_id]['amount'] = $line_item_wrapper->commerce_unit_price->amount
->value();
}
}
}
}
// Add custom submit/validate handlers for recording transactions.
$form['actions']['submit']['#validate'][] = 'commerce_gc_validate_order_form_giftcard_transactions';
$form['actions']['submit']['#submit'][] = 'commerce_gc_submit_order_form_giftcard_transactions';
}