Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
function commerce_auction_place_bid_form_submit($form, &$form_state) {
$node = $form_state['#node'];
$timeout_field = field_get_items('node', $node, 'auction_timeout');
if (!isset($timeout_field) || empty($timeout_field) || !$timeout_field[0]['value']) {
drupal_set_message(t('Auction timeout has no value, Please first set a value for the timeout field.'), 'error');
}
field_attach_submit('commerce_auction_bid', $form_state['#entity'], $form, $form_state);
global $user;
// Save entity (new commerce_auction_bid entity that contains the bid amount
// entered in the form.)
$entity = $form_state['#entity'];
$entity->uid = $user->uid;
$entity->created = REQUEST_TIME;
$amount = commerce_currency_amount_to_decimal($entity->bid_amount[LANGUAGE_NONE][0]['amount'], commerce_default_currency());
$entity->title = $user->name . ' (' . $amount . ')';
$entity->save();
// Update node, so that it references this bid too,
$delta = (empty($node->auction_bid_refs[LANGUAGE_NONE])) ? 0 : max(array_keys($node->auction_bid_refs[LANGUAGE_NONE])) + 1;
$node->auction_bid_refs[LANGUAGE_NONE][$delta]['target_id'] = $entity->id;
// Update highest bid on display node.
// This makes creating per-user bidding tables easier.
$node->auction_highest_bid[LANGUAGE_NONE][0] = $entity->bid_amount[LANGUAGE_NONE][0];
// If we are in the last 15 minutes of the auction timeout,
// Extend timeout for 30minutes
$expiration_timestamp = $timeout_field[0]['value'];
$time_period = variable_get('commerce_auction_final_period', 15) * 60;
$extension_time = variable_get('commerce_auction_extension_time', 30) * 60;
$extend_timeout = variable_get('commerce_auction_extend', TRUE);
if ($extend_timeout &&
$expiration_timestamp - REQUEST_TIME < $time_period &&
$expiration_timestamp - REQUEST_TIME > 0) {
$timeout_field[0]['value'] = $extension_time + $expiration_timestamp;
}
$node->auction_timeout[LANGUAGE_NONE][0]['value'] = $timeout_field[0]['value'];
// Now that everything is updated, save the node!
node_save($node);
drupal_set_message(t('Your bid is saved!'));
drupal_goto('node/' . $node->nid);
}
Due to usage of drupal_goto() above , when I add a custom submit handler using hook_form_alter , it does not execute code inside the custom submit handler, I would suggest adding $form_state['redirect'] = 'node/'. $node->nid;
I would like to add a patch for the same.
would request someone to help me on how to add a patch?
Comment | File | Size | Author |
---|---|---|---|
#2 | 2779553-2.patch | 2.43 KB | hash6 |
Comments
Comment #2
hash6 CreditAttribution: hash6 commentedComment #3
hash6 CreditAttribution: hash6 commented