Add to cart formatter settings form incorrectly sets "line_item_type" to 0 when only 1 line item type.
In the code below from commerce_cart_field_formatter_settings_form() line 2327:
The commerce_product_line_item_types() returns an array of line items type names numerically keyed. If there is only 1 line item type, the setting value is set to 0.

    $types = commerce_product_line_item_types();

    if (count($types) > 1) {
      $element['line_item_type'] = array(
        '#type' => 'select',
        '#title' => t('Add to Cart line item type'),
        '#options' => array_intersect_key(commerce_line_item_type_get_name(), drupal_map_assoc($types)),
        '#default_value' => $settings['line_item_type'],
      );
    }
    else {
      $element['line_item_type'] = array(
        '#type' => 'hidden',
        '#value' => key($types),
      );
    }

Comments

recrit’s picture

Status: Active » Needs review
StatusFileSize
new473 bytes

The attached patch changes it to use reset instead of key.

rszrama’s picture

Status: Needs review » Fixed

Good catch! Looks like it's only worked thanks to a fluke re: empty() an an affordance to ensure the new setting worked when added to existing sites. : P

Committed.

Status: Fixed » Closed (fixed)

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

Status: Closed (fixed) » Needs work

The last submitted patch, 1: commerce-cart-formatter-default-line-type-2156205-1.patch, failed testing.

rszrama’s picture

Status: Needs work » Closed (fixed)