function commerce_coupon_commerce_cart_order_refresh in Commerce Coupon 7
Same name and namespace in other branches
- 7.2 commerce_coupon.module \commerce_coupon_commerce_cart_order_refresh()
Implements hook_commerce_cart_order_refresh().
If the coupon has been removed from the order somehow, keep consistency.
File
- ./
commerce_coupon.module, line 1075 - Coupon System for Drupal Commerce.
Code
function commerce_coupon_commerce_cart_order_refresh($order_wrapper) {
$order = $order_wrapper
->value();
$coupons = $order_wrapper->commerce_coupon_order_reference
->value();
foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
$line_item = $line_item_wrapper
->value();
if ($line_item->type == 'commerce_coupon') {
$coupon = $line_item_wrapper->commerce_coupon_reference
->value();
if (!in_array($coupon, $coupons)) {
commerce_coupon_remove_coupon_from_order($order, $coupon);
}
}
}
}