View source
<?php
function commerce_eu_vat_rc_commerce_customer_profile_type_info() {
$profile_types = array();
$profile_types['eu_vat_rc'] = array(
'type' => 'eu_vat_rc',
'name' => t('EU VAT information'),
'description' => t('The profile used to collect VAT information on the checkout and order forms.'),
'addressfield' => FALSE,
'help' => '',
'checkout_pane_weight' => 0,
);
return $profile_types;
}
function commerce_eu_vat_rc_configure_customer_types() {
commerce_customer_profile_types_reset();
if ($profile_type = commerce_customer_profile_type_load('eu_vat_rc')) {
if (!field_info_field_types('vat_number')) {
field_cache_clear();
}
$field_name = 'commerce_vat_number';
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_customer_profile', $field_name, $profile_type['type']);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'vat_number',
'cardinality' => 1,
'entity_types' => array(
'commerce_customer_profile',
),
'translatable' => FALSE,
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_customer_profile',
'bundle' => $profile_type['type'],
'label' => t('VAT Number'),
'required' => FALSE,
'widget' => array(
'type' => 'vat_number_widget',
'weight' => -10,
'settings' => array(),
),
'display' => array(),
);
field_create_instance($instance);
}
}
}
function commerce_eu_vat_rc_form_commerce_checkout_form_checkout_alter(&$form, $form_state, $form_id) {
if (isset($form['customer_profile_eu_vat_rc'])) {
$eu_countries = _commerce_eu_vat_eu_countries();
$visible_conditions = array();
foreach ($eu_countries as $iso => $name) {
$visible_conditions[]['value'] = $iso;
}
$form['customer_profile_eu_vat_rc']['#states'] = array(
'visible' => array(
':input[name="customer_profile_billing[commerce_customer_address][und][0][country]"]' => $visible_conditions,
),
);
}
}