Set Entries field in Commerce order on completion I'm trying to set an Entries field within a Commerce Order once the order completes.

I've tried using the onOrderComplete event like so;

craft()-&gt;on('commerce_orders.onOrderComplete',function($event){    
    $order = $event-&gt;params['order'];

    $order-&gt;setContent(array( 'calculation' =&gt; 678 )); // magic number for testing
    craft()-&gt;commerce_orders-&gt;saveOrder($order);    
});


and also;

 craft()-&gt;on('commerce_orders.onOrderComplete',function($event){    
     $order = $event-&gt;params['order'];

     $order-&gt;calculation = 678; // magic number for testing
     craft()-&gt;commerce_orders-&gt;saveOrder($order);    
 });


With no luck.

I have also tried setting the field value on the add to cart form with

&lt;input type="hidden" name="fields[calculation][]" value="678"&gt;


Again with no luck (I am using MultiAdd so thought it might not be working because of that).

Can anyone point me in the right direction here?
See What is getContent() / the ContentModel, and how do I use it to get and set custom field values?

So you needed to change the method used for setting content on an element.

Also see In a plugin, how do I save an entry with a related entry

So the relation fields always expect an array of ids, even if there is a single relation. 

Putting those together you should be able to do:

craft()-&gt;on('commerce_orders.onOrderComplete',function($event){    
    $order = $event-&gt;params['order'];

    $order-&gt;setContentFromPost(['entryRelaionFieldName' =&gt; [678] ]);

    craft()-&gt;commerce_orders-&gt;saveOrder($order);    
});