[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

jamescook’s picture

Issue summary: View changes
jamescook’s picture

Issue summary: View changes
jamescook’s picture

Issue summary: View changes
jamescook’s picture

Just 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

   $something = entity_save('order', $order);

as I suggested above is not reliable (works sometimes, sometimes not - DB is not always updated)

Instead use

        commerce_order_save($order);

That's working here

rszrama’s picture

Status: Active » Closed (fixed)

Thanks for the update; I've occasionally seen a difference in save functions as well. Never had a chance to track down why.