function commerce_coupon_commerce_cart_order_refresh in Commerce Coupon 7.2
Same name and namespace in other branches
- 7 commerce_coupon.module \commerce_coupon_commerce_cart_order_refresh()
Implements hook_commerce_cart_order_refresh().
File
- ./
commerce_coupon.module, line 1378 - Provides coupon functionality for Drupal Commerce.
Code
function commerce_coupon_commerce_cart_order_refresh($order_wrapper) {
$order = $order_wrapper
->value();
if (!commerce_coupon_order_allows_coupons($order)) {
return;
}
foreach ($order_wrapper->commerce_coupons
->value() as $coupon) {
// Invalidate coupons that exist on the order without their discount
// present, meaning an inline condition on the discount was not satisfied.
// Free shipping discounts often do not apply immediately. For this reason,
// do not remove coupon codes that exclusively grant free shipping.
if ($coupon && $coupon->type == 'discount_coupon' && !commerce_coupon_order_coupon_code_discounts($coupon->code, $order) && !_commerce_coupon_free_shipping_single_discount($coupon)) {
// Remove invalid coupons.
commerce_coupon_remove_coupon_from_order($order, $coupon, FALSE);
$error =& drupal_static('commerce_coupon_error_' . strtolower($coupon->code));
if (!$error) {
// Set a generic error message unless something has.
$error = t('Unable to redeem coupon.');
}
}
}
}