You are here

function commerce_coupon_redeem_coupon in Commerce Coupon 7

Redeem a coupon. For calculating the coupon value the rules engine is used.

Parameters

$coupon: The coupon to redeem.

$order: The order on which the coupon should be redeemed.

Return value

void

3 calls to commerce_coupon_redeem_coupon()
commerce_coupon_handler_area_cart_form_submit in includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
Submit: function commerce_coupon_handler_area_cart_form.
commerce_coupon_pane_checkout_form in includes/commerce_coupon.checkout_pane.inc
Payment pane: form callback.
commerce_coupon_pane_checkout_form_submit in includes/commerce_coupon.checkout_pane.inc
We have a valid coupon code, so submit it.

File

./commerce_coupon.module, line 272
Coupon System for Drupal Commerce.

Code

function commerce_coupon_redeem_coupon($coupon, $order) {
  if (!isset($order->order_id) or !isset($coupon->coupon_id)) {
    drupal_set_message(t('Your coupon code cannot be redeemed.'), 'error');
    return;
  }

  // We invoke the rule. The defined action callback methods sets then the
  // coupon value appropriate.
  rules_invoke_event('commerce_coupon_redeem', $coupon, $order);
  commerce_order_save($order);
}