1
Answers
Saving into a customer profile field
Hey,
Hey, im trying to save into a customer profile field. Reading it out is no problem:
if(!empty($order_wrapper->commerce_customer_billing->field_shop_annotations)) {
$annotations = $order_wrapper->commerce_customer_billing->field_shop_annotations->value();
}
But saving into gives me an error message. Here's my code:
// Save annotations
$order = commerce_cart_order_load($user->uid);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$annotations = $form_state['values']['annotations'];
$profile_id = $order_wrapper->commerce_customer_billing->profile_id->value();
$profile = commerce_customer_profile_load($profile_id);
if ($profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile)) {
// This gives me the error message:
$profile_wrapper->commerce_customer_billing->field_shop_annotations->set('muh');
}
Everthing works fine except the set method inside the if clause. I also tried:
$profile_wrapper->commerce_customer_billing->field_shop_annotations->value = $annotations;
Comments
You could also try just:
<?php
$order_id = 12;
$order = commerce_order_load($order_id);
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$wrapper->commerce_customer_billing->value()->field_shop_annotations->set('my_value');
$wrapper->save();
?>