2

i've coded a checkout complete but aint triggering other modules checkout complete rules, i'm assuming commerce_checkout_complete($order->order_id); will do this.

The most important thing for me is that, the items on the cart are files, hence i have commerce licence that grant license to each files which is not triggered by the code below. Any tips on how to do this please?

Thank you very much.

<?php
    function custom_module_complete_order($order_id) {

     $order = commerce_order_load($order_id);

     commerce_order_status_update($order, 'checkout_checkout');

      $payment_method = commerce_payment_method_instance_load('commerce_payment_example|commerce_payment_commerce_payment_example');

      $transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
      $transaction->instance_id = $payment_method['instance_id'];
      $transaction->amount = $order->commerce_order_total['und'][0]['amount'];
      $transaction->currency_code = $order->commerce_order_total['und'][0]['currency_code'];
      $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
      $transaction->message = 'Name: @name';
      $transaction->message_variables = array('@name' => 'Commerce Cartmaker Payment');

      commerce_payment_transaction_save($transaction);
      commerce_payment_commerce_payment_transaction_insert($transaction);

     commerce_order_save($order);
     commerce_checkout_complete($order->order_id);
}
?>
1
  • Sorry stackexchange says i need to wait 2 days to check my answer.
    – axscode
    Commented Sep 24, 2015 at 0:26

2 Answers 2

1

Updating to checkout_complete status, make the code works. Thanks.

+     $order = commerce_order_status_update($order, 'checkout_complete');
      commerce_order_save($order);
      commerce_checkout_complete($order->order_id);
0

Axscode's answer will probably work (untested but I believe in you axscode ;) ) But to eleborate. Like alter hooks, rules events are called via code. Possibly after all hooks have finished running (this is how it works for the product add form for example). Snippet:

  // Allow modules to prepare this as necessary. This hook is defined by the
  // Product Pricing module.
  drupal_alter('commerce_product_calculate_sell_price_line_item', $line_item);

  // Process the unit price through Rules so it reflects the user's actual
  // purchase price.
  rules_invoke_event('commerce_product_calculate_sell_price', $line_item);

So to make it work you'll have to call the rules even manually via something like rules_invoke_event('commerce_product_calculate_sell_price', $line_item); you'll have to dig trough commerce code for the right rules event.

1
  • @Surnga, Thank you very much for that. $order = commerce_order_status_update($order, 'checkout_complete') is the key to call the checkout_complete rules even not invoking rules_invoke_event("commerce_checkout_complete", $order);
    – axscode
    Commented Sep 22, 2015 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.