function commerce_product_bundle_configure_line_item in Commerce Product Bundle 7.2
Same name and namespace in other branches
- 7 commerce_product_bundle.module \commerce_product_bundle_configure_line_item()
Ensures the product line item type contains a product reference field.
This function is called by the line item module when it is enabled or this module is enabled. It invokes this function using the configuration_callback as specified above.
1 string reference to 'commerce_product_bundle_configure_line_item'
File
- ./
commerce_product_bundle.module, line 1202 - Allows the bundling of products in Drupal Commerce.
Code
function commerce_product_bundle_configure_line_item() {
commerce_product_reference_create_instance('commerce_product', 'commerce_line_item', 'bundle', t('Bundled Product'));
// Look for or add a display path textfield to the product line item type.
$field_name = 'commerce_display_path';
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_line_item', $field_name, 'bundle');
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'text',
'cardinality' => 1,
'entity_types' => array(
'commerce_line_item',
),
'translatable' => FALSE,
'locked' => TRUE,
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_line_item',
'bundle' => 'bundle',
'label' => t('Display path'),
'required' => TRUE,
'settings' => array(),
'widget' => array(
'type' => 'text_textfield',
),
'display' => array(
'display' => array(
'label' => 'hidden',
'weight' => -10,
),
),
);
field_create_instance($instance);
}
// Setup the related commerce_line_item:
$field_name = 'commerce_parent_line_item';
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_line_item', $field_name, 'bundle');
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'commerce_line_item_reference',
'cardinality' => 1,
'entity_types' => array(
'commerce_line_item',
),
'translatable' => FALSE,
'locked' => TRUE,
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_line_item',
'bundle' => 'bundle',
'label' => t('Parent Line Item'),
'required' => TRUE,
'settings' => array(),
'widget' => array(
'type' => 'commerce_line_item_manager',
),
'display' => array(
'display' => array(
'label' => 'hidden',
'weight' => -10,
),
),
);
field_create_instance($instance);
}
}