How can a new Customer profile type be created
We need a second customer profile type: We need to have a shipping address on all of our orders. I see a list of profile types at admin/commerce/customer-profiles/types -- much like one can view a list of content types for nodes elsewhere in Drupal. However, in the list of profile types, there is only the billing information type listed and there is no link to create additional profile types.
I would think a need for a shipping address would already have come up for shops currently using Commerce. What is the method to create new customer profile types or what is another solution for shipping addresses in Commerce?
Comments
You can add fields to entities
The beauty of Commerce is that you get to add fields where you need them.
So add a new field to your customer profile type at admin/commerce/customer-profiles/types/billing/fields
Ahah!
Ahah! I can't believe I didn't think of that -- that will also prevent generating twice as many entities per Order as well! Randy comes to the rescue again! Thank you!!
Whatever I build custom onto Commerce, I want to do with best practices -- both in the general sense and specific to optimizing and extended Commerce as it was intended to be extended and leveraged. And I'm not 100% clear on all of that as it pertains to Commerce. So, because the customer profile is also called the customer *billing* profile, I figured the best practice/intentions was to also create a parallel entity for customer shipping profiles.
I wonder what the developer of the AddressBook module has to say about this?
...I know a lot of Commerce's extensibility is still barely in infancy, but my long-term vision (/assumption?) is that our store can all of the standard features of a mature store -- address books, wish lists, etc. An address book is top on my list, and I wonder what the best way to build additional addresses on to an order is so that they will all be included in the list of addresses for a customer provided by the AddressBook?
For example, will AddressBook pull all AddressFields from any linked customer profile -- in which case your suggestion of two AddressFields on the same entity will work; or does it need to be some hardcoded or primary and singular AddressField per customer profile -- in which case, creating a second customer profile entity for the second/shipping address would be advisable?
From what I've been reading it's starting to seem like creating a new customer profile type is a hardcoded process, i.e. via a module, rather than just being able to do it from the web admin pages.
How to create another customer profile type
OK, just a summary for anyone else looking, here's how to create a new commerce_customer_profile type
<?php
/**
* Implementation of hook_commerce_customer_profile_type_info
*/
function example_commerce_customer_profile_type_info() {
$profile_types = array();
$profile_types['profile_info'] = array(
'type' => 'profile_info',
'name' => t('Profile information'),
'description' => t('The profile used to collect personal information on the checkout and order forms.'),
'help' => '',
'addressfield' => FALSE
);
return $profile_types;
}
?>
commerce_customer_configure_customer_profile_type('profile_info');
commerce_order_configure_customer_profile_type('profile_info', 'Profile information');
I used a hook_update_N to run
<?php
/**
* Configure fieldablility on commerce customer profile_info type and
* also related profile reference field on commerce order
*/
function example_update_7005(&$sandbox) {
commerce_customer_configure_customer_profile_type('profile_info');
commerce_order_configure_customer_profile_type('profile_info', 'Profile information');
$sandbox['#finished'] = TRUE;
return t('Enabled fields on the commerce customer profile type: Profile Information. Configured profile reference field on commerce_order');
}
?>
After that, everything works perfectly.
Thanks!
David, thanks for this code -
David, thanks for this code - been looking for this for a while. However, I tried to use this to create a new customer profile type. My module installs without errors, but the new profile type still doesnt show up under the Drupal 7 => Store = > Customer Profile Types section.
Please tell me what I have done wrong.
I created a file called customer_profile.module. Below is my source code:
<?php
/**
* Implementation of hook_commerce_customer_profile_type_info
*/
function custom_commerce_customer_profile_type_info() {
$profile_types = array();
$profile_types['profile_info'] = array(
'type' => 'profile_info',
'name' => t('Profile information'),
'description' => t('The profile used to collect personal information on the checkout and order forms.'),
'help' => '',
'addressfield' => FALSE
);
custom_update_commerce_order($sandbox);
return $profile_types;
}
/**
* Configure fieldablility on commerce customer profile_info type and
* also related profile reference field on commerce order
*/
function custom_update_commerce_order(&$sandbox) {
commerce_customer_configure_customer_profile_type('profile_info');
commerce_order_configure_customer_profile_type('profile_info', 'Profile information');
$sandbox['#finished'] = TRUE;
return t('Enabled fields on the commerce customer profile type: Profile Information. Configured profile reference field on commerce_order');
}
Waiting eagerly for your reply.
Thanks in advance
Dries
Any reply on this, please?
I just managed to sort this
I just managed to sort this out, my new customer profile type now shows. Now I am wondering if to disable to default Billing Profile, since I intend to include customer addresses in my new profile. Is this in line with Drupal Commerce design principles? Or am I missing something? I'm thinking it would be a little bit cumbersome on the system - if 2 customer profile types are submitted with EACH new order.
Any ideas, please?