Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm not sure why this Rules component should result in a warning
{ "rules_increment_standard_shipping" : {
"LABEL" : "Increment standard shipping",
"PLUGIN" : "rule",
"REQUIRES" : [ "rules", "commerce_line_item" ],
"USES VARIABLES" : {
"list_item" : { "label" : "List item", "type" : "commerce_line_item" },
"shipping_line_item" : { "label" : "Shipping line item", "type" : "commerce_line_item" }
},
"IF" : [
{ "entity_has_field" : { "entity" : [ "list-item" ], "field" : "commerce_product" } }
],
"DO" : [
{ "data_calc" : {
"USING" : { "input_1" : [ "list-item:quantity" ], "op" : "*", "input_2" : "400" },
"PROVIDE" : { "result" : { "result" : "Calculation result" } }
}
},
{ "commerce_line_item_unit_price_add" : {
"commerce_line_item" : [ "shipping-line-item" ],
"amount" : [ "result" ],
"component_name" : "flat_rate_standard_shipping",
"round_mode" : "1"
}
}
]
}
}
The warning:
Warning: Illegal string offset 'type' in rules_action_data_calc() (line 78 of /Users/rszrama/src/git/drupal/rules/modules/data.eval.inc).
All I'm doing is multiplying the quantity of a line item (an integer) by the number 400. I get the warning, but the data value still calculates properly and I can use it in subsequent actions to increment the unit price of a shipping line item. The code seems to be expecting the $var_info variable to be an array, but in my case it's just a string containing 'result'.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1843174-1.data_value_var_info.patch | 590 bytes | rszrama |
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedAttached is a patch that solves the ensure by ensuring $var_info is an array and has a 'type' key. Not sure if it needs to be solved deeper, though.
Comment #2
smokrisDuplicate of #1776582: Warning: Illegal string offset 'type' in rules_action_data_calc() . (Comment #5 on that case has a patch that solves the root problem instead of just avoiding the warning.)