[Using Rules 7.x-2.6]
I've added some fields to Commerce Order at /admin/commerce/config/order/fields
I have a rules Action which saves some text to one of these new (text) fields on a new Order.
I use the standard "Save Entity" with "Force Immediate" option.
Condition:
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "field_some_text" } },
:
Action (part):
"DO" : [
:
:
{ "data_set" : {
"data" : [ "commerce-order:field_some_text" ],
"value" : { "value" : { "value" : "Some text", "format" : "filtered_html" } }
}
},
{ "entity_save" : { "data" : [ "commerce-order" ], "immediate" : 1 } },
But the new fields are never saved.
They are somehow "locally" present - I can fetch the object and print out the changed field from the new fields (in the SAME rule). But no commited change is taking place, i.e. no database change.
My workaround has been to create actions to set these fields:
function MYMODULE_set_some_text_field_action($order, $text)
{
$order->field_some_text['und'][0]['value'] = $text;
entity_save('order', $order);
}
which works fine (action called in rule).
But surely, the Rules alone should work?
Comments
Comment #1
jamescook CreditAttribution: jamescook commentedComment #2
jamescook CreditAttribution: jamescook commentedComment #3
jamescook CreditAttribution: jamescook commentedComment #4
jamescook CreditAttribution: jamescook commentedJust to add - updating fields with commerce_order entity save in a rule really doesn't work.
The local commerce_order in cache/memory is updated but not flushed to the DB.
Even implementing an action with
as I suggested above is not reliable (works sometimes, sometimes not - DB is not always updated)
Instead use
That's working here
Comment #5
rszrama CreditAttribution: rszrama commentedThanks for the update; I've occasionally seen a difference in save functions as well. Never had a chance to track down why.