You are here

function commerce_gc_order_giftcard_amount in Commerce GC 7

Determine the amount of a particular giftcard that is eligible to apply to apply against an order. Uses a static cache.

Parameters

EntityDrupalWrapper $order_wrapper:

EntityDrupalWrapper $coupon_wrapper:

type $exclude_amount:

type $reset:

Return value

type

1 call to commerce_gc_order_giftcard_amount()
commerce_gc_commerce_cart_order_refresh in ./commerce_gc.module

File

./commerce_gc.module, line 306
Provides Giftcard coupon bundle, Giftcard Transaction entity and basic user interface elements.

Code

function commerce_gc_order_giftcard_amount(EntityDrupalWrapper $order_wrapper, EntityDrupalWrapper $coupon_wrapper, $reset = FALSE) {
  $cache =& drupal_static(__FUNCTION__);
  $coupon_id = $coupon_wrapper->coupon_id
    ->value();
  if ($reset || !isset($cache[$coupon_id])) {
    $order_amount = $order_wrapper->commerce_order_total->amount
      ->value();

    // Calculate the amount of the giftcard that may be applied.
    $balance_amount = commerce_gc_giftcard_balance($coupon_id);
    $cache[$coupon_id] = $order_amount < $balance_amount ? $order_amount : $balance_amount;
  }
  return $cache[$coupon_id];
}