commerce_billy.install in Commerce Billy 7
Commerce Billy installation file.
File
commerce_billy.installView source
<?php
/**
* @file
* Commerce Billy installation file.
*/
/**
* Implements hook_uninstall().
*/
function commerce_billy_uninstall() {
variable_del('commerce_billy_invoice_nr_method');
variable_del('commerce_billy_auto_invoice');
variable_del('commerce_billy_invoice_nr_pattern');
variable_del('commerce_billy_invoice_nr_last');
variable_del('commerce_billy_invoice_nr_padding');
}
/**
* Update Commerce Billy variables.
*/
function commerce_billy_update_7100() {
$pattern_old = variable_get('commerce_billy_invoice_nr_pattern', '[invoice_nr]');
$selected_method = variable_get('commerce_billy_invoice_nr_method', COMMERCE_BILLY_INVOICE_METHOD_YEARLY);
switch ($selected_method) {
case COMMERCE_BILLY_INVOICE_METHOD_INFINITE:
$last_number = commerce_billy_query_variable('commerce_billy_invoice_nr_last_infinite');
$new_nr_array = array(
'id' => isset($last_number) ? $last_number : 0,
);
variable_set('commerce_billy_invoice_nr_last', $new_nr_array);
$pattern_new = str_replace('[invoice_nr]', '{id}', $pattern_old);
variable_set('commerce_billy_invoice_nr_pattern', $pattern_new);
break;
case COMMERCE_BILLY_INVOICE_METHOD_YEARLY:
$last_number = commerce_billy_query_variable('commerce_billy_invoice_nr_last_yearly');
if ($last_number) {
$parts = explode('-', $last_number);
$new_nr_array = array(
'year' => $parts[0],
'id' => $parts[1],
);
}
else {
$new_nr_array = array(
'year' => date('Y'),
'id' => 0,
);
}
variable_set('commerce_billy_invoice_nr_last', $new_nr_array);
$pattern_new = str_replace('[invoice_nr]', '[date:custom:Y]-{id}', $pattern_old);
variable_set('commerce_billy_invoice_nr_pattern', $pattern_new);
break;
case COMMERCE_BILLY_INVOICE_METHOD_MONTHLY:
$last_number = commerce_billy_query_variable('commerce_billy_invoice_nr_last_monthly');
if ($last_number) {
$parts = explode('-', $last_number);
$new_nr_array = array(
'year' => $parts[0],
'month' => $parts[1],
'id' => $parts[2],
);
}
else {
$new_nr_array = array(
'year' => date('Y'),
'month' => date('m'),
'id' => 0,
);
}
variable_set('commerce_billy_invoice_nr_last', $new_nr_array);
$pattern_new = str_replace('[invoice_nr]', '[date:custom:Y-m]-{id}', $pattern_old);
variable_set('commerce_billy_invoice_nr_pattern', $pattern_new);
break;
}
variable_del('commerce_billy_invoice_nr_last_infinite');
variable_del('commerce_billy_invoice_nr_last_yearly');
variable_del('commerce_billy_invoice_nr_last_monthly');
}
/**
* Invoice and cancel dates: Set field default value to "blank".
*/
function commerce_billy_update_7101() {
$entity_info = entity_get_info('commerce_order');
$order_types = array_keys($entity_info['bundles']);
drupal_alter('commerce_billy_order_types', $order_types);
$fields = array(
'field_commerce_billy_cancel_date',
'field_commerce_billy_i_date',
);
foreach ($fields as $field_name) {
foreach ($order_types as $order_type) {
$instance = field_info_instance('commerce_order', $field_name, $order_type);
if ($instance) {
$instance['settings']['default_value'] = 'blank';
field_update_instance($instance);
}
}
}
}
Functions
Name![]() |
Description |
---|---|
commerce_billy_uninstall | Implements hook_uninstall(). |
commerce_billy_update_7100 | Update Commerce Billy variables. |
commerce_billy_update_7101 | Invoice and cancel dates: Set field default value to "blank". |