Short: I have commerce product and commerce discount that affects this product's price. I want to presents details of this discount to users in shop.

Long story: I use Drupal Commerce with Drupal Commerce Discount which is based on Rules. Discount module is used for configuring promotions on products. Some of promotion (configured discounts) are time-limited ie. they ends on 11.11.2015. I would like to get information about discounts that affect product when displaying details. First of all I need to display information how much time is left before discount ends.

Is there any way to get information about active rules on product level?

1 Answer 1


On the line item, you have the field_unit_price field. Inside of that field's data attribute, you'll find information about the discounts that are applied to that product:

array(1) {
  array(2) {
    array(3) {
      string(22) "discount|discount_test"
      array(3) {
        string(3) "USD"
        array(2) {
          string(13) "discount_test"
          string(5) "Test"

Iterate over the components. If there is a discount applied to one of the items, you'll find one with a name that begins with discount|. Then you can then load that discount and grab more information about it:

$discount = entity_load('commerce_discount', array('discount_test'));

From here, if you've added dates, the date fields will be accessible on the field commerce_discount_date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.