The commerce_cart_order_convert() function just adds "commerce_customer_" to the front of the profile type to determine its reference field.

This means that profile types created by contributed modules result in a crash like this one:

EntityMetadataWrapperException: Unknown data property commerce_customer_<em>type</em>. in EntityStructureWrapper->getPropertyInfo() (line 339 of sites/all/modules/entity/includes/entity.wrapper.inc).
The website encountered an unexpected error. Please try again later.

I think this is the only occurrence of this in Commerce.

Files: 
CommentFileSizeAuthor
#6 by-instances-1838936.patch2.63 KBnicholaspaun
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch by-instances-1838936.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#4 combined-1838936.patch1.39 KBnicholaspaun
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]
#2 fix-commerce-order-hardcode-1838936.patch739 bytesnicholaspaun
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]
#1 fix-hardcode-1838936.patch687 bytesnicholaspaun
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new687 bytes
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]

Here's the patch.

Title:commerce_cart_order_convert() uses hard-coded names for profile reference fieldsFix hard-coded profile field names
StatusFileSize
new739 bytes
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]

Oops...
I found another one in commerce_order_order_form_submit().

Status:Needs review» Needs work

Let's combine these into a single patch. One problem I see may be the fact that the profile type -> reference field name association comes from checkout pane settings, so we can't reliably use that in the Order module (which doesn't depend on Checkout).

Additionally, is this not just an incompatibility with some other module? Customer Profile types should be defined in modules and have reference fields created during install. Perhaps some module allows you to create new types but doesn't create the fields the same way?

Status:Needs work» Needs review
StatusFileSize
new1.39 KB
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]

Here is the combined patch file.
Did I get this right?

I don't quite understand the part about reference fields being created at install. Should all reference fields use the format commerce_customer_type? Shouldn't user-created reference fields be in the the format field_type (for example) or am I confused?

Perhaps it would be better to iterate over the commerce_profile_reference type fields in an order to avoid depending on Checkout?

Title:Fix hard-coded profile field namesAllow cart order / administrative order conversion to work for any customer profile reference field
Component:Cart» Developer experience
Category:bug» feature
Status:Needs review» Needs work

I suppose the idea is that as designed the system can only accommodate these automatically generated reference fields. The main reason, of course, is that there is no general UI to map these things together. There are a few places where in the absence of a UI (or really the lack of desire to add one) we've made assumptions around field names and form structures.

However, we can do one better than this patch and open this up to support any customer profile reference field. In these two places, instead of relying either on a field naming pattern or a checkout pane setting, let's just loop over the field instances on the order, look for customer profile reference fields, and update them all that way instead of coming in through the customer profile types list.

Think that's something you can do or would you prefer to punt?

Status:Needs work» Needs review
StatusFileSize
new2.63 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch by-instances-1838936.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Thank you very much for being so patient with me. I think I got it now.
How's this patch?

Status:Needs review» Fixed

It's perfect! Exactly what I was thinking. Welcome to the committers log. : )

Commit: http://drupalcode.org/project/commerce.git/commitdiff/0bd2775

Thank you!

Shows up on your user profile, too. ; )

http://drupal.org/user/642646

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.