Is it possible to setup a coupon type to have a field where the user can select roles that can use that coupon? I don't see roles listed as an entity that can be referenced.

Thanks

Comments

pcambra’s picture

Status: Active » Fixed

I think you can do this with the Role reference module as roles are not entities whatsoever.

deggertsen’s picture

Thank you. I will try that.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

deggertsen’s picture

Status: Closed (fixed) » Closed (works as designed)

This is not working at the moment because it appears that the Role reference module is not currently integrated with rules. I have created an issue for that module regarding this. #1617880: Rules Integration

wqmeng’s picture

Status: Closed (works as designed) » Active

Hello.

Do you have succeeded to do this? Limit a coupon code only used by the user with a role?

I have tried add a role reference in a coupon type and data compare with the user's role with the coupon role reference, but it seems not work.

Do you work it out?

Thanks

citlacom’s picture

Status: Active » Fixed

The patch in http://drupal.org/node/1372398 resolve the problem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

deggertsen’s picture

@wqmeng I have a rule for this now. You must have the role reference module with a role reference field on your coupon (I called it field_limit_to_roles). I have not really tested this yet, but here's the export:

{ "rules_coupon_validation_check_authorized_roles" : {
    "LABEL" : "Coupon Validation: Check authorized roles",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "coupon" ],
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_validate" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "field_limit_to_roles" } },
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : [ "coupon:field-limit-to-roles" ],
          "operation" : "OR"
        }
      },
      { "NOT data_is_empty" : { "data" : [ "coupon:field-limit-to-roles" ] } }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "Sorry, you are not authorized to use this coupon.",
          "type" : "error"
        }
      },
      { "commerce_coupon_action_is_invalid_coupon" : [] }
    ]
  }
}