1

I'm trying to set the value of a custom field on an order when saving an entry. I found an example of how to do this for a simple text field, but the field I'm trying to set is an entries field, not just a text field. I've attempted to set the value using the following code in my entries.saveEntry event. I'm assuming I'm doing this wrong since this is an entries field, not a simple text field, but I don't know the syntax for setting content on an entries field.

$cart = craft()->commerce_cart->getCart();
$cart->setContentFromPost(['entriesFieldHandle' => $entry->id]);

1 Answer 1

4

I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field.

Since an entries field is an array of elements, not just a single element, I just needed to set the value of the field as an array instead of a string.

Changing

$cart->setContentFromPost(['entriesFieldHandle' => $entry->id]);

to

$cart->setContentFromPost(['entriesFieldHandle' => [$entry->id]]);

seemed to do the trick.

To zoom in a little more, the value needs to be set with 'entriesFieldHandle' => [$entry->id] instead of 'entriesFieldHandle' => $entry->id.

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.