diff --git a/modules/customer/includes/commerce_customer.checkout_pane.inc b/modules/customer/includes/commerce_customer.checkout_pane.inc index e0d7311..b725720 100644 --- a/modules/customer/includes/commerce_customer.checkout_pane.inc +++ b/modules/customer/includes/commerce_customer.checkout_pane.inc @@ -42,22 +42,32 @@ function commerce_customer_profile_pane_settings_form($checkout_pane) { if (count($profile_types)) { $form['commerce_' . $checkout_pane['pane_id'] . '_profile_copy'] = array( '#type' => 'checkbox', - '#title' => t('Allow this profile to use values from another profile, where applicable.'), - '#description' => t('For example, use the shipping information as the billing information.'), + '#title' => t('Enable profile copying on this checkout pane, helping customers avoid having to enter the same address twice.'), '#default_value' => variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy', FALSE), ); - $form['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_source'] = array( - '#type' => 'select', - '#title' => t('Source of profile information'), - '#options' => $profile_types, - '#default_value' => variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_source', NULL), + $form['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_wrapper'] = array( + '#type' => 'fieldset', + '#title' => t('Profile copy options'), '#states' => array( 'visible' => array( ':input[name="commerce_' . $checkout_pane['pane_id'] . '_profile_copy"]' => array('checked' => TRUE), ), ), ); + + $form['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_wrapper']['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_source'] = array( + '#type' => 'select', + '#title' => t('Profile to copy from'), + '#options' => $profile_types, + '#default_value' => variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_source', NULL), + ); + + $form['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_wrapper']['commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default'] = array( + '#type' => 'checkbox', + '#title' => t('Make copying information from this profile the default action, requiring users to uncheck a box on the checkout pane to enter a different address.'), + '#default_value' => variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', TRUE), + ); } return $form; @@ -110,6 +120,8 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec // customer profile, add a checkbox to allow users to toggle this. if (variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy', FALSE) && $source_profile_type_name = variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_source', NULL)) { + // Load the default profile copy option from settings. + $profile_copy_default = variable_get('commerce_' . $checkout_pane['pane_id'] . '_profile_copy_default', FALSE); // Make sure our profile type still exists.. if ($source_profile_type = commerce_customer_profile_type_load($source_profile_type_name)) { @@ -121,7 +133,7 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec '#type' => 'checkbox', '#title' => t('My @target is the same as my @source.', array('@target' => drupal_strtolower($target_profile_type['name']), '@source' => drupal_strtolower($source_profile_type['name']))), '#element_validate' => array('commerce_customer_profile_copy_validate'), - '#default_value' => isset($order->data['profile_copy'][$checkout_pane['pane_id']]['status']) ? $order->data['profile_copy'][$checkout_pane['pane_id']]['status'] : FALSE, + '#default_value' => isset($order->data['profile_copy'][$checkout_pane['pane_id']]['status']) ? $order->data['profile_copy'][$checkout_pane['pane_id']]['status'] : $profile_copy_default, '#weight' => -30, '#ajax' => array( 'callback' => 'commerce_customer_profile_copy_refresh', @@ -145,6 +157,17 @@ function commerce_customer_profile_pane_checkout_form($form, &$form_state, $chec } } } + // If profile copy action has not been set and the default action TRUE. + elseif (empty($order->data['profile_copy']) && $profile_copy_default) { + // Get field names that will be copied from the source profile. + foreach (field_info_instances('commerce_customer_profile', $source_profile_type['type']) as $field_name => $field) { + $langcode = $pane_form[$field_name]['#language']; + // If the field exists on the destination profile then disable it. + if(!empty($pane_form[$field_name])){ + $pane_form[$field_name][$langcode]['#access'] = FALSE; + } + } + } } } diff --git a/modules/customer/tests/commerce_customer_ui.test b/modules/customer/tests/commerce_customer_ui.test index 808c01f..77f371c 100644 --- a/modules/customer/tests/commerce_customer_ui.test +++ b/modules/customer/tests/commerce_customer_ui.test @@ -558,9 +558,23 @@ class CommerceCustomerUITest extends CommerceBaseTestCase { } /** - * Test the copying of one profile's fields to another. + * Test the copying of one profile's fields to another (disabled by default). */ public function testCommerceCustomerUIProfileCopy() { + $this->_testCommerceCustomerUIProfileCopy(); + } + + /** + * Test the copying of one profile's fields to another (enabled by default). + */ + public function testCommerceCustomerUIProfileCopyDefaultEnabled() { + $this->_testCommerceCustomerUIProfileCopy(TRUE); + } + + /** + * Test the copying of one profile's fields to another. + */ + public function _testCommerceCustomerUIProfileCopy($default_enabled = FALSE) { // Enable the helper module that creates a new profile type. module_enable(array('commerce_customer_profile_dummy_type')); @@ -568,6 +582,7 @@ class CommerceCustomerUITest extends CommerceBaseTestCase { // the billing information customer profile type. variable_set('commerce_customer_profile_dummy_profile_copy', TRUE); variable_set('commerce_customer_profile_dummy_profile_copy_source', 'billing'); + variable_set('commerce_customer_profile_dummy_profile_copy_default', $default_enabled); // Create an order. $order = $this->createDummyOrder($this->store_customer->uid); @@ -579,9 +594,11 @@ class CommerceCustomerUITest extends CommerceBaseTestCase { // Generate random information, as city, postal code, etc. $address_info = $this->generateAddressInformation(); - // Fill in the billing address information - $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]"); - $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']); + // Fill in the billing address information if the copying isn't enabled by default. + if (!$default_enabled) { + $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]"); + $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']); + } // Fill in the required information for billing pane, with a random State. $info = array(