Addressbook attaches a field to profiles that allows the user to specify whether that is his "default" address.
This is something that is safe to change even when the profile is already referenced from an order.
So there should be a way to tell commerce_order_commerce_customer_profile_presave() to ignore certain fields when doing the comparison of "did the fields change, should I duplicate the profile?"

I don't know a nice way to do this. Perhaps a key on the entity that gets unset in the end?

CommentFileSizeAuthor
#2 1317426.patch1.33 KBbojanz
#1 1317426.patch770 bytesbojanz

Comments

bojanz’s picture

Status: Active » Needs review
StatusFileSize
new770 bytes

Something like this perhaps? Doesn't feel very nice, but does the job.

Either an approach such as that one, or advising people for avoiding field api fields for use cases such as this one.

bojanz’s picture

StatusFileSize
new1.33 KB

Tweaked it a bit.

czigor’s picture

Do I understand correctly: the idea is to add the $profile->_ignore_fields somewhere in a hook_form_commerce_checkout_form_checkout_alter()?

So far, I have been doing this by adding an #element_validate callback in hook_form_commerce_checkout_form_checkout_alter() and unsetting the unwanted field there in $form_state['values']. I could do this because I only needed that field for some AJAX form handling.

svendecabooter’s picture

bojanz’s picture