Commerce Coupon Percentage Amount doesn't create an individual line item when a coupon is applied, instead it adds a discount price component to each line item. The function commerce_coupon_remove_coupon_from_order() doesn't cater for this case.

I have found a solution for this, although because I also found I need to apply the patch from https://drupal.org/comment/7633515#comment-7633515 I haven't tested my solution in its absence.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alfaguru’s picture

Haven't the time to create a patch so just pasting the code in here for now.

<?php
  
  $coupon_wrapper = entity_metadata_wrapper('commerce_coupon', $coupon);
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    $line_item_wrapper->commerce_unit_price->data = commerce_price_component_delete($line_item_wrapper->commerce_unit_price->value(), $coupon_wrapper->price_component_name->value());    
    $line_item_wrapper->save();
  }

?>
alfaguru’s picture