commerce_gc.install in Commerce GC 7
Installs Giftcard transaction table and default fields.
File
commerce_gc.installView source
<?php
/**
* @file
* Installs Giftcard transaction table and default fields.
*/
/*
* Implements hook_schema().
*/
function commerce_gc_schema() {
$schema['commerce_gc_transaction'] = array(
'description' => 'The table for keeping track of giftcard transactions.',
'fields' => array(
'transaction_id' => array(
'description' => 'The identifier for this transaction.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'coupon_id' => array(
'description' => 'An identifier for a coupon.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'date' => array(
'description' => 'The Unix timestamp when the transaction occurred.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'amount' => array(
'description' => 'The transaction amount.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'The status of this transaction (hold, completed, cancelled).',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
),
'primary key' => array(
'transaction_id',
),
'indexes' => array(
'coupon_id' => array(
'coupon_id',
),
),
'foreign keys' => array(
'coupon_id' => array(
'table' => 'commerce_coupon',
'columns' => array(
'coupon_id' => 'coupon_id',
),
),
),
);
return $schema;
}
/*
* Implements hook_install().
*/
function commerce_gc_install() {
_commerce_gc_install_helper();
}
/**
* Helper function to set up fields
*/
function _commerce_gc_install_helper() {
field_info_cache_clear();
$fields = field_info_fields();
$instances = field_info_instances();
// Add an inline conditions field.
_commerce_coupon_install_inline_conditions_field();
/*
* 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_coupon']['giftcard_coupon']['commerce_gc_value'])) {
$instance = array(
'field_name' => 'commerce_gc_value',
'entity_type' => 'commerce_coupon',
'bundle' => 'giftcard_coupon',
'label' => t('Value'),
'required' => TRUE,
);
field_create_instance($instance);
}
/*
* Giftcard name
*/
if (empty($fields['commerce_gc_name'])) {
// Create max uses field.
$field = array(
'field_name' => 'commerce_gc_name',
'type' => 'text',
'locked' => TRUE,
'cardinality' => '1',
);
field_create_field($field);
}
if (empty($instances['commerce_coupon']['giftcard_coupon']['commerce_gc_name'])) {
$instance = array(
'field_name' => 'commerce_gc_name',
'entity_type' => 'commerce_coupon',
'bundle' => 'giftcard_coupon',
'label' => t('Name'),
);
field_create_instance($instance);
}
}
/*
* Implements hook_uninstall().
*/
function commerce_gc_uninstall() {
// Remove field data for giftcard bundle.
commerce_delete_instances('commerce_coupon', 'giftcard_coupon');
// For giftcard use line item:
commerce_delete_instances('commerce_line_item', 'giftcard_use');
}
/**
* Change "completed" status to "complete".
*/
function commerce_gc_update_7001() {
// Change "completed" status to complete.
db_update('commerce_gc_transaction')
->condition('status', 'completed')
->fields(array(
'status' => 'complete',
))
->execute();
}
/**
* Add inline conditions field.
*/
function commerce_gc_update_7002() {
// Add an inline conditions field.
_commerce_coupon_install_inline_conditions_field();
}
/**
* Disable deprecated Commerce Giftcard Discount module.
*/
function commerce_gc_update_7003() {
// Add an inline conditions field.
module_disable(array(
'commerce_gc_discount',
));
}
Functions
Name | Description |
---|---|
commerce_gc_install | |
commerce_gc_schema | |
commerce_gc_uninstall | |
commerce_gc_update_7001 | Change "completed" status to "complete". |
commerce_gc_update_7002 | Add inline conditions field. |
commerce_gc_update_7003 | Disable deprecated Commerce Giftcard Discount module. |
_commerce_gc_install_helper | Helper function to set up fields |