You are here

function uc_coupon_uc_cart_alter in Ubercart Discount Coupons 7.2

Same name and namespace in other branches
  1. 6 uc_coupon.module \uc_coupon_uc_cart_alter()
  2. 7.3 uc_coupon.module \uc_coupon_uc_cart_alter()

Implements hook_uc_cart_alter().

This is called every time the cart is rebuild (e.g. when products are added), so it's a good place to revalidate our session coupons. We also add a fake cart item (if configured to show in cart) for each coupon. These will be removed at checkout.

File

./uc_coupon.module, line 1635

Code

function uc_coupon_uc_cart_alter(&$items) {
  $coupons = uc_coupon_session_validate($items);

  // Validate all codes in the session against the cart contents.
  if (variable_get('uc_coupon_show_in_cart', TRUE) && !empty($coupons)) {

    // If there are some valid coupons, then add them to the cart.
    foreach ($coupons as $code => $coupon) {
      $items[] = _uc_coupon_cart_item($coupon);
    }
  }
}