function _uc_coupon_cart_item in Ubercart Discount Coupons 7.3
Same name and namespace in other branches
- 7.2 uc_coupon.module \_uc_coupon_cart_item()
Creates a fake cart-item corrresponding to this coupon, allowing this coupon to be displayed in the cart.
Parameters
$coupon: The coupon to be displayed in the cart.
2 calls to _uc_coupon_cart_item()
- uc_coupon_form_uc_cart_checkout_form_alter in ./
uc_coupon.module - Implements hook_form_FORM_ID_alter() for uc_cart_checkout_form().
- uc_coupon_uc_cart_alter in ./
uc_coupon.module - Implements hook_uc_cart_alter().
File
- ./
uc_coupon.module, line 1840 - Provides discount codes and gift certificates for Ubercart.
Code
function _uc_coupon_cart_item($coupon) {
// Exclude any line-item discounts from the amount shown in the cart.
$amount = 0;
foreach ($coupon->discounts as $id => $discount) {
if (is_numeric($id) && $id > 0) {
$amount += $discount->discount;
}
}
// Assign this a unique cart_item_id so it will be keyed properly by entity_view().
$id = -hexdec(substr(sha1($coupon->code), -8));
return (object) array(
'cart_item_id' => $id,
'module' => 'uc_coupon',
'title' => $coupon->title,
'nid' => 0,
'qty' => 1,
'price' => -$amount,
'data' => array(
'module' => 'uc_coupon',
'shippable' => FALSE,
'code' => $coupon->code,
'remove' => uc_coupon_session_get($coupon->code),
),
'model' => 0,
'weight' => 0,
);
}