This feature is similar to http://drupal.org/node/1407498.

My use case was a monthly sale set with pricing calculation rules, that should not be applied when certain coupons had been applied to the order.

The condition is configured on the price calculation rule after a call to entity has field 'commerce_coupon_order_reference' using the order from the line item and a directly specified coupon.

Files: 

Comments

dopry’s picture

Status:Active» Needs review
pcambra’s picture

Status:Needs review» Needs work
+++ b/commerce_coupon.rules.inc
@@ -47,6 +47,35 @@ function commerce_coupon_rules_event_info() {
+ * Implements hook_rules_condition_info() ¶

Please fix the extra spaces

+++ b/commerce_coupon.rules.inc
@@ -47,6 +47,35 @@ function commerce_coupon_rules_event_info() {
+    'label' => t('Order has a specific coupon'),

Wording improvement suggestion: "Coupon has been applied to an order"

+++ b/commerce_coupon.rules.inc
@@ -47,6 +47,35 @@ function commerce_coupon_rules_event_info() {
+ 'description' => 'The order to be checked for the coupon.'

Missing t()

+++ b/commerce_coupon.rules.inc
@@ -232,3 +261,13 @@ function commerce_coupon_action_remove_all_coupons_from_order($order) {
+  if (empty($order)) return true;

Not following drupal standards for ifs

+++ b/commerce_coupon.rules.inc
@@ -232,3 +261,13 @@ function commerce_coupon_action_remove_all_coupons_from_order($order) {
+  if (empty($coupon)) return true;

Same here

+++ b/commerce_coupon.rules.inc
@@ -232,3 +261,13 @@ function commerce_coupon_action_remove_all_coupons_from_order($order) {
+  return in_array($coupon->coupon_id, $order_wrapper->commerce_coupon_order_reference->raw());

Coupons may be disabled, status = 0, so we may want to create an api function with uses entity field query for this

Horroshow’s picture

Thanks for the patch

aidanlis’s picture

if (empty($order)) return true; What's the logic behind that? Shouldn't we return FALSE if either of the parameters is invalid?

Also be good to specify whether the coupon identifier is the coupon string or the raw ID.

ssoulless’s picture

Issue summary:View changes
Status:Needs work» Patch (to be ported)

I think this patch should be recreated for use wtin 2.x branch, also fixing the problems that @pcambra already said.

ssoulless’s picture

ok I do not understand why is necesarry this part in the patch

+/**
  * Implements hook_rules_action_info().
  */
function commerce_coupon_rules_action_info() {
@@ -232,3 +261,13 @@ function commerce_coupon_action_remove_all_coupons_from_order($order) {
   }
   commerce_coupon_remove_all_coupons_from_order($order);
}

Should be removed

ssoulless’s picture

and regarding the comment of @aindalis, yes it would be better idea to specify that the condition checks for the coupon raw id and not the coupon code itself, but would be better idea to change to be the "coupon code" because is more friendly for the users...