You are here

function commerce_cart_field_instance_attribute_settings in Commerce Core 7

Returns an array of attribute settings for a field instance.

Fields attached to product types may be used as product attribute fields with selection widgets on Add to Cart forms. This function returns the default values for a given field instance.

Parameters

$instance: The info array of the field instance whose attribute settings should be retrieved.

Return value

An array of attribute settings including:

  • attribute_field: boolean indicating whether or not the instance should be used as a product attribute field on the Add to Cart form; defaults to FALSE
  • attribute_widget: string indicating the type of form element to use on the Add to Cart form for customers to select the attribute option; defaults to 'select', may also be 'radios'
  • attribute_widget_title: string used as the title of the attribute form element on the Add to Cart form.
4 calls to commerce_cart_field_instance_attribute_settings()
commerce_cart_add_to_cart_form in modules/cart/commerce_cart.module
Builds an Add to Cart form for a set of products.
commerce_cart_attribute_widget_title in modules/cart/commerce_cart.module
Returns the title of an attribute widget for the Add to Cart form.
commerce_cart_field_instance_is_attribute in modules/cart/commerce_cart.module
Determines whether or not a field instance is fucntioning as a product attribute field.
commerce_cart_form_field_ui_field_edit_form_alter in modules/cart/commerce_cart.module
Implements hook_form_FORM_ID_alter().

File

modules/cart/commerce_cart.module, line 1590
Implements the shopping cart system and add to cart features.

Code

function commerce_cart_field_instance_attribute_settings($instance) {
  if (empty($instance['commerce_cart_settings']) || !is_array($instance['commerce_cart_settings'])) {
    $commerce_cart_settings = array();
  }
  else {
    $commerce_cart_settings = $instance['commerce_cart_settings'];
  }

  // Supply default values for the cart settings pertaining here to
  // product attribute fields.
  $commerce_cart_settings += array(
    'attribute_field' => FALSE,
    'attribute_widget' => 'select',
    'attribute_widget_title' => '',
  );
  return $commerce_cart_settings;
}