function basic_cart_update_7200 in Basic cart 7.2
Same name and namespace in other branches
- 7.3 basic_cart.install \basic_cart_update_7200()
Adding Basic Cart new features (price, currency).
File
- ./
basic_cart.install, line 117 - Basic cart install file
Code
function basic_cart_update_7200() {
// Setting up the default currency.
variable_set('basic_cart_currency', BASIC_CART_DEFAULT_CURRENCY);
// Check to see if the price field already exists.
$field = field_info_field('price');
// If the price field does not exist then create it.
if (empty($field)) {
$field = array(
'field_name' => 'price',
'type' => 'number_decimal',
'entity_types' => array(
'node',
),
);
field_create_field($field);
}
// Getting the content types for which we have basic cart active.
$node_types = variable_get('basic_cart_content_types');
if (is_array($node_types)) {
// Setting up the price field for the selected content types.
foreach ($node_types as $type => $checked) {
// If a node type is checked, then create the price field.
if ($checked) {
// Foreach checked content type, we must assign the price field to the content type.
$instance = field_info_instance('node', 'price', $type);
if (empty($instance)) {
$instance = array(
'field_name' => 'price',
'label' => t('Price'),
'description' => t('Please enter the price for this item.'),
'entity_type' => 'node',
'bundle' => $type,
);
// It doesn't exist. Create it.
field_create_instance($instance);
}
}
else {
$instance = field_info_instance('node', 'price', $type);
if (!empty($instance)) {
field_delete_instance($instance);
}
}
}
}
}