1

I've enabled the Commerce Fees module and added a rule with the following details:

{ "rules_setup_fee" : {
    "LABEL" : "Setup Fee",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce License Billing" ],
    "REQUIRES" : [ "rules", "commerce_fees" ],
    "ON" : { "commerce_fees_order" : [] },
    "IF" : [
      { "text_matches" : {
          "text" : [ "commerce-order:commerce-line-items:0:line-item-label" ],
          "match" : "book"
        }
      }
    ],
    "DO" : [
      { "commerce_fees_apply" : {
          "entity" : [ "commerce-order" ],
          "fee" : "setup_fee",
          "amount" : "999",
          "currency_code" : "USD"
        }
      }
    ]
  }
}

which correctly adds $9.99 setup fee to a shopping cart when customer selects any product which has the "book" string in its title (or SKU which we try to keep the same). So the whole thing serves its purpose just fine, however unfortunately it also leaves the following traces in the logs:

Unable to evaluate condition text_matches. Unable to get the data value for the variable or parameter text. Error: Unable to get the data property line_item_label as the parent data structure is not set.

What am I doing wrong here? Thanks!

1 Answer 1

0

You should add a data_exists to ensure that the delta/label you're trying to access actually exists. It looks like line-item-label is a custom property.

8
  • Nick, I am not sure if I should post this question separately, but it's relevant. The above rule works fine now without giving any errors, however the log is full of "Reacting on event Apply a fee to a given order." messages. Seems like the rule is invoked even if nobody is going to order page, is it normal or should I re-write my rule?
    – Nick
    Jan 13, 2016 at 12:36
  • 1
    What version of commerce are you using?
    – nvahalik
    Jan 13, 2016 at 13:20
  • It shows Commerce 7.x-1.11 in the modules page.
    – Nick
    Jan 13, 2016 at 13:47
  • 1
    Without looking at the code, it's hard to say, but as long as there are no errors, it sounds like debugging is just turned on and adding stuff to the log. The rules will re-apply on order refresh which can happen on every page load.
    – nvahalik
    Jan 13, 2016 at 14:03
  • O yea, I enabled debug logs on admin/config/workflow/rules/settings, but is it really normal that this particular rule is invoked on every page load? The reason I am worried is that other rules are invoked only when needed.
    – Nick
    Jan 13, 2016 at 14:34

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.