The checkout form is a form like any other, so you can just alter it (using hook_form_alter()
) and add a submit handler:
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_form_commerce_cart_form_default') {
$form['#submit'][] = 'MYMODULE_some_function';
}
}
function MYMODULE_some_function($form, &$form_state) {
drupal_set_message('This was run after the cart form was submitted, before the checkout page was rendered.');
}
Addressing the comments...
As you have a custom shopping cart form, with a link instead of submit button, no extra processing will be done so you can just hook into the page build of the linked page (/checkout/%) and perform your operation there; it will have the same effect.
There are a couple of places you could do this (neither really 'better' than the other), hook_page_alter()
and hook_init()
. There are other places too (theme preprocess functions) but for processing logic something a bit earlier is probably more appropriate. Basic example (will probably need tweaking for your needs):
function MYMODULE_init() {
if (arg(0) == 'checkout' && $some_other_pertinent_condition) {
// Do some processing.
}
}
As for learning Commerce - that's a tricky one. Commerce is heavily integrated with Drupal and uses a lot of its functions/hooks/integrations just like any other module would. So really you need to know Drupal's workflow, and then overlay Commerce's workflow on top of that. The best advise I can give is to grab a Drupal book (Pro Drupal Development is excellent), and after you're happy with the workflow there, hit the Drupal Commerce support pages and read, read, read.
Drupal has a notoriously steep learning curve, and there isn't really a shortcut to understanding how it works as a whole. You just have to get stuck in. But it's well worth it, Drupal's awesome.