You are here

function uc_coupon_uc_cart_alter in Ubercart Discount Coupons 6

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

Implementation of hook_uc_cart_alter().

If a coupon is in use, add it as a (fake) cart item. This will be converted to a real line item during checkout.

File

./uc_coupon.module, line 1239
Provides discount coupons for Ubercart.

Code

function uc_coupon_uc_cart_alter(&$items, $ignore = NULL) {
  if (variable_get('uc_coupon_show_in_cart', TRUE) && isset($_SESSION['uc_coupon'])) {
    $coupon = uc_coupon_validate($_SESSION['uc_coupon']);
    if ($coupon->valid) {
      $items[] = (object) array(
        'module' => 'uc_coupon',
        'coupon' => $coupon,
        'title' => $coupon->title,
        'nid' => 0,
        'qty' => 1,
        'price' => uc_coupon_price(-$coupon->amount, 'altered'),
        'data' => array(
          'shippable' => FALSE,
        ),
      );
    }
  }
}