View source
<?php
function commerce_recurring_uninstall() {
foreach (array_keys(_commerce_recurring_installed_fields()) as $field) {
field_delete_field($field);
}
field_purge_batch(1000);
commerce_product_ui_product_type_delete('recurring', FALSE);
}
function commerce_recurring_install() {
$product_type = commerce_product_ui_product_type_new();
$product_type['type'] = 'recurring';
$product_type['name'] = t('Recurring product');
$product_type['description'] = t('A recurring purchase product type.');
$product_type['is_new'] = TRUE;
commerce_product_ui_product_type_save($product_type, FALSE);
commerce_price_create_instance('commerce_price', 'commerce_product', 'recurring', t('Price'), 0, 'calculated_sell_price');
if (!field_info_field_types('commerce_order_reference') || !field_info_field_types('interval') || !field_info_field_types('datestamp')) {
field_cache_clear();
}
entity_info_cache_clear();
foreach (_commerce_recurring_installed_fields() as $field_name => $field_detail) {
$field = field_info_field($field_name);
if (empty($field)) {
$field = field_create_field($field_detail);
}
}
foreach (_commerce_recurring_installed_instances() as $field_name => $instance_detail) {
$instance = field_info_instance($instance_detail['entity_type'], $field_name, $instance_detail['bundle']);
if (empty($instance)) {
field_create_instance($instance_detail);
}
}
commerce_order_configure_order_type('recurring_order');
}
function _commerce_recurring_installed_fields() {
$t = get_t();
return array(
'commerce_recurring_interval' => array(
'field_name' => 'commerce_recurring_interval',
'cardinality' => 1,
'type' => 'interval',
),
'commerce_recurring_parent_order' => array(
'field_name' => 'commerce_recurring_parent_order',
'cardinality' => 1,
'type' => 'commerce_order_reference',
'settings' => array(
'referenceable_types' => array(
'commerce_order' => $t('Order'),
),
'field_injection' => FALSE,
),
),
'commerce_recurring_next_due' => array(
'field_name' => 'commerce_recurring_next_due',
'cardinality' => 1,
'type' => 'datestamp',
'settings' => array(
'granularity' => array(
'day' => 'day',
'hour' => 0,
'minute' => 0,
'month' => 'month',
'second' => 0,
'year' => 'year',
),
'repeat' => 0,
'timezone_db' => 'UTC',
'todate' => '',
'tz_handling' => 'none',
),
),
'commerce_recurring_payment_due' => array(
'field_name' => 'commerce_recurring_payment_due',
'cardinality' => 1,
'type' => 'datestamp',
'settings' => array(
'granularity' => array(
'day' => 'day',
'hour' => 0,
'minute' => 0,
'month' => 'month',
'second' => 0,
'year' => 'year',
),
'repeat' => 0,
'timezone_db' => 'UTC',
'todate' => '',
'tz_handling' => 'none',
),
),
'commerce_recurring_payment' => array(
'field_name' => 'commerce_recurring_payment',
'cardinality' => 1,
'type' => 'list_boolean',
'settings' => array(
'allowed_values' => array(
0 => $t('Unprocessed'),
1 => $t('Processed'),
),
),
),
);
}
function _commerce_recurring_installed_instances() {
$t = get_t();
return array(
'commerce_recurring_interval' => array(
'entity_type' => 'commerce_product',
'bundle' => 'recurring',
'field_name' => 'commerce_recurring_interval',
'label' => $t('Billing interval'),
'widget' => array(
'type' => 'interval_default',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'interval_default',
),
),
'settings' => array(
'allowed_periods' => array(
'day' => 'day',
'week' => 'week',
'month' => 'month',
),
),
),
'commerce_recurring_payment' => array(
'entity_type' => 'commerce_order',
'bundle' => 'recurring_order',
'field_name' => 'commerce_recurring_payment',
'label' => $t('Payment Processed'),
'widget' => array(
'type' => 'options_select',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'list_default',
),
),
),
'commerce_recurring_parent_order' => array(
'entity_type' => 'commerce_order',
'bundle' => 'recurring_order',
'field_name' => 'commerce_recurring_parent_order',
'label' => $t('Parent Order.'),
'widget' => array(
'type' => 'options_select',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'commerce_order_reference_link',
),
),
),
'commerce_recurring_payment_due' => array(
'entity_type' => 'commerce_order',
'bundle' => 'recurring_order',
'field_name' => 'commerce_recurring_payment_due',
'label' => $t('Payment Due.'),
'widget' => array(
'settings' => array(
'increment' => '15',
'input_format' => 'm/d/Y',
'default_value' => 'blank',
'input_format_custom' => '',
'label_position' => 'above',
'repeat_collapsed' => 0,
'text_parts' => array(),
'year_range' => '-3:+3',
),
'type' => 'date_popup',
),
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'date',
'settings' => array(
'format_type' => 'long',
'fromto' => 'both',
'multiple_from' => '',
'multiple_number' => '',
'multiple_to' => '',
'show_repeat_rule' => 'show',
),
'type' => 'date_default',
),
),
),
'commerce_recurring_next_due' => array(
'entity_type' => 'commerce_order',
'bundle' => 'commerce_order',
'field_name' => 'commerce_recurring_next_due',
'label' => $t('Next Invoice.'),
'widget' => array(
'settings' => array(
'increment' => '15',
'default_value' => 'blank',
'input_format' => 'm/d/Y',
'input_format_custom' => '',
'label_position' => 'above',
'repeat_collapsed' => 0,
'text_parts' => array(),
'year_range' => '-3:+3',
),
'type' => 'date_popup',
),
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'date',
'settings' => array(
'format_type' => 'long',
'fromto' => 'both',
'multiple_from' => '',
'multiple_number' => '',
'multiple_to' => '',
'show_repeat_rule' => 'show',
),
'type' => 'date_default',
),
),
),
);
}
function commerce_recurring_update_7001() {
$field_name = 'commerce_recurring_payment';
$field = field_info_field($field_name);
$field_details = _commerce_recurring_installed_fields();
$field_detail = $field_details[$field_name];
if (empty($field)) {
$field = field_create_field($field_detail);
}
$instance_details = _commerce_recurring_installed_instances();
$instance_detail = $instance_details[$field_name];
$instance = field_info_instance($instance_detail['entity_type'], $field_name, $instance_detail['bundle']);
if (empty($instance)) {
field_create_instance($instance_detail);
}
include_once './includes/install.inc';
module_list(TRUE);
system_rebuild_module_data();
module_enable(array(
'commerce_cardonfile',
));
return t('Added payment status field to the recurring order type. If you have existing recurring orders, please set their payment processing status to unprocessed.');
}