The 2nd variable_get() in commerce_customer_profile_pane_checkout_form_submit() is unnecessary, the variable has already been got.

Comments

czigor created an issue. See original summary.

czigor’s picture

Status: Active » Needs review
StatusFileSize
new736 bytes
mglaman’s picture

Status: Needs review » Needs work
/**
 * Checkout pane callback: returns a customer profile edit form.
 */
function commerce_customer_profile_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
  $pane_form = array('#parents' => array($checkout_pane['pane_id']));

  // Extract the type of profile represented by this pane from its ID.
  $type = substr($checkout_pane['pane_id'], 17); // Removes 'customer_profile_'

  // Find the referenced profile using the related reference field...
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $profile = NULL;

  // If the associated order field has been set...
  if ($field_name = variable_get('commerce_' . $checkout_pane['pane_id'] . '_field', '')) {
    // Check to ensure the specified profile reference field exists on the
    // current order type.
    if (!field_info_instance('commerce_order', $field_name, $order->type)) {
      return array();
    }

    $profile = $wrapper->{$field_name}->value();
  }

We actually do need this. And I suppose we need to review the tests.

mglaman’s picture

Component: Developer experience » Customer
czigor’s picture

Status: Needs work » Needs review

I'm not sure we are talking about the same variable_get(). There are 2 variable_get()s in commerce_customer_profile_pane_checkout_form_submit(). The 2nd one fetches the same variable as the 1st, so it's not needed.

mglaman’s picture

Title: Unnecessary variable_get() in neo_commerce_profile_checkout_pane_submit() » Unnecessary variable_get() in commerce_customer_profile_pane_checkout_form_submit()

Whoops O:) I looked at form and not submit, sorry. You are correct.

Beginning of function

  // Check to ensure the specified profile reference field exists on the
  // current order type.
  $field_name = variable_get('commerce_' . $pane_id . '_field', '');

And this portion of the patch

if ($field_name = variable_get('commerce_' . $checkout_pane['pane_id'] . '_field', '')) {

What do you think about changing the title a bit and adding this other fix: there's no need to initiate an order wrapped if the field is empty. This is only used if the field name is not empty, so it should be initiated in that same check.

  // Store the profile ID for the related field as specified on the settings form.
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
czigor’s picture

Title: Unnecessary variable_get() in commerce_customer_profile_pane_checkout_form_submit() » Small performance improvements in commerce_customer_profile_pane_checkout_form_submit()
Issue summary: View changes
StatusFileSize
new850 bytes

No wonder, I was using the wrong function name in the title and the description. :|

I have fixed the wrapper thing, too.

mglaman’s picture

Issue tags: +Commerce Sprint, +Quick fix

:)

smccabe’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, both changes are small and don't actually change any functionality, just make things a little cleaner.

rszrama’s picture

Category: Bug report » Task
Status: Reviewed & tested by the community » Fixed

Committed.

  • rszrama committed d761caa on 7.x-1.x authored by czigor
    Issue #2678718 by czigor: Small performance improvements in...

Status: Fixed » Closed (fixed)

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