Skip to content

Instantly share code, notes, and snippets.

@heshanlk
Last active November 15, 2017 11:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heshanlk/625ab587f7130ddffd39 to your computer and use it in GitHub Desktop.
Save heshanlk/625ab587f7130ddffd39 to your computer and use it in GitHub Desktop.
Drupal Commerce Coupon - Limit one coupon per order rule

#Drupal Commerce Coupon - Limit one coupon per order rule

{ "rules_no_double_coupons" : {
    "LABEL" : "No double coupons",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : { "commerce_coupon_applied_to_cart" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "commerce_coupons" } },
      { "list_count_is" : {
          "list" : [ "commerce-order:commerce-coupons" ],
          "op" : "\u003E",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "You cannot use more than 1 coupon for the same order.",
          "type" : "error"
        }
      },
      { "list_remove" : {
          "list" : [ "commerce-order:commerce-coupons" ],
          "item" : [ "commerce-coupon" ]
        }
      },
      { "entity_save" : { "data" : [ "commerce-order" ], "immediate" : "1" } }
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment