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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nicholaspaun’s picture

Status: Active » Needs review
FileSize
687 bytes

Here's the patch.

nicholaspaun’s picture

Title: commerce_cart_order_convert() uses hard-coded names for profile reference fields » Fix hard-coded profile field names
FileSize
739 bytes

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

rszrama’s picture

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?

nicholaspaun’s picture

Status: Needs work » Needs review
FileSize
1.39 KB

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?

rszrama’s picture

Title: Fix hard-coded profile field names » Allow 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?

nicholaspaun’s picture

Status: Needs work » Needs review
FileSize
2.63 KB

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

rszrama’s picture

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

nicholaspaun’s picture

Thank you!

rszrama’s picture

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.