function _commerce_gc_product_install_helper in Commerce GC 7
Install default fields.
2 calls to _commerce_gc_product_install_helper()
- commerce_gc_product_flush_caches in modules/
commerce_gc_product/ commerce_gc_product.module - commerce_gc_product_install in modules/
commerce_gc_product/ commerce_gc_product.install
File
- modules/
commerce_gc_product/ commerce_gc_product.install, line 11 - Installs default giftcard product fields.
Code
function _commerce_gc_product_install_helper() {
field_info_cache_clear();
$fields = field_info_fields();
$instances = field_info_instances();
/*
* Product giftcard value
*/
if (empty($fields['commerce_gc_value'])) {
// Create max uses field.
$field = array(
'field_name' => 'commerce_gc_value',
'type' => 'commerce_price',
'locked' => TRUE,
'cardinality' => '1',
);
field_create_field($field);
}
if (empty($instances['commerce_product']['giftcard']['commerce_gc_value'])) {
$instance = array(
'field_name' => 'commerce_gc_value',
'entity_type' => 'commerce_product',
'bundle' => 'giftcard',
'label' => t('Giftcard value'),
'required' => TRUE,
);
field_create_instance($instance);
}
/*
* Free product line items: Giftcard coupon reference
*/
if (module_exists('commerce_discount')) {
if (empty($fields['commerce_giftcards'])) {
// Create giftcard reference field
$field = array(
'settings' => array(
'target_type' => 'commerce_coupon',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array(
'product_display' => 'giftcard_coupon',
),
),
),
'field_name' => 'commerce_giftcards',
'type' => 'entityreference',
'locked' => TRUE,
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
}
if (empty($instances['commerce_line_item']['product_discount']['commerce_giftcards'])) {
$instance = array(
'label' => t('Purchased giftcards'),
'widget' => array(
'type' => 'entityreference_autocomplete',
'weight' => '9',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => 60,
'path' => '',
),
),
'field_name' => 'commerce_giftcards',
'entity_type' => 'commerce_line_item',
'bundle' => 'product_discount',
'default_value' => NULL,
);
field_create_instance($instance);
}
}
}