I recently needed the ability to apply a coupon to an order based on whether or not the order contained products with certain attribute select list values. This is an extension of what Ubercart already offers except it checks for actual values set against an order, rather than if an attribute exists.

I wrote this patch and I'm submitting it here in case someone else requires similar functionality.

This method will also work with UC Coupon Workflow to allow the automated application of coupons when certain order conditions are met. For this to work properly, you will need to create a coupon with "All matching product(s)" since this is a product-level modification. If you need it to work with other coupons, you will need to configure that as well under "Combinations".

This also requires a patch against uc_attributes to allow checking a product-level attribute setting. This could probably be incorporated into the uc_coupon patch, but for now this is how it is.

Here is a sample rule I'm using on my site:

{ "rules_10_off_for_kindergarten_registration" : {
    "LABEL" : "$10 off for Kindergarten Registration",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Checkout" ],
    "REQUIRES" : [ "uc_coupon_workflow" ],
    "ON" : { "uc_coupon_workflow_automatic" : [] },
    "DO" : [
      { "uc_coupon_workflow_apply" : {
          "USING" : { "cid" : "54", "mode" : "auto" },
          "PROVIDE" : { "coupon" : { "coupon" : "Coupon" } }
        }
      }
    ]
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merauluka created an issue.

tyrese.hamblin’s picture

Amazing patch. Very useful! Thank you! This would be perfect if you could select more than 1 attribute.