Question

I'm trying to execute some business logic after the checkout process in Drupal 7 with Drupal commerce module. I've read on the documentation that I can use the hook hook_commerce_checkout_complete but it's not called

function api_manager_commerce_checkout_complete($order) {
    $ow = entity_metadata_wrapper('commerce_order', $order);

    foreach ($ow->commerce_line_items as $line_item) {
     $sku = $line_item->commerce_product->sku->value();

     $record = array(
      'uid' => get_user_id(),
      'sku' => $sku,
      'token' => uniqid(),
     );

     drupal_write_record('api_manager_product_user', $record);
    }

}

For your information, I've disabled 'payment' and 'billing information' in the checkout configuration

Was it helpful?

Solution

Whenever a new hook is implemented in Drupal you are required to clear your cache ( class ). Only then would that particular hook be available and fired when invoked.

If you are using devel module, you can check out if your hook is recognized by the system by Drupal by using module_implements function. Devel module gives you a convenient tool at http://www.mysite.com/devel/php to try out such snippets.

dpm(module_implements('commerce_checkout_complete'));

If your module's name is not listed as the output of the above function then it means your hook is not recognized. As mentioned earlier please clear your cache in such case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top