commerce_custom_offline_payment.features.inc in Commerce Custom Offline Payments 7
File
commerce_custom_offline_payment.features.inc
View source
<?php
function commerce_custom_offline_payment_features_export($data, &$export, $module_name = '') {
$pipe = array();
$export['dependencies']['features'] = 'features';
$export['dependencies']['commerce_payment'] = 'commerce_payment';
$export['dependencies']['commerce_cop'] = 'commerce_cop';
$export['dependencies']['rules'] = 'rules';
$payments = commerce_cop_get_payments();
foreach ($data as $payment_id) {
$export['features']['commerce_custom_offline_payment'][$payment_id] = $payment_id;
}
return $pipe;
}
function commerce_custom_offline_payment_features_export_options() {
$feature_types = array();
$payments = commerce_cop_get_payments();
if (!empty($payments)) {
foreach ($payments as $payment) {
$feature_types[$payment['id']] = $payment['title'];
}
}
return $feature_types;
}
function commerce_custom_offline_payment_features_export_render($module, $data, $export = NULL) {
$payments = commerce_cop_get_payments();
$output = array();
$output[] = ' $items = array(';
foreach ($data as $payment_id) {
if (isset($payments[$payment_id]) && ($payment = $payments[$payment_id])) {
$output[] = " '{$payment_id}' => " . features_var_export($payment, ' ') . ",";
}
}
$output[] = ' );';
$output[] = ' return $items;';
$output = implode("\n", $output);
return array(
'commerce_custom_offline_payments' => $output,
);
}
function commerce_custom_offline_payment_features_revert($module = NULL) {
if (module_hook($module, 'commerce_custom_offline_payments')) {
$default_payments = module_invoke($module, 'commerce_custom_offline_payments');
$existing_payments = commerce_cop_get_payments();
foreach ($default_payments as $default_payment) {
if (!isset($existing_payments[$default_payment['id']])) {
$default_payment['is_new'] = TRUE;
}
commerce_cop_payment_save($default_payment);
}
}
else {
drupal_set_message(t('Could not load default payments.'), 'error');
return FALSE;
}
entity_defaults_rebuild();
rules_clear_cache(TRUE);
variable_set('menu_rebuild_needed', TRUE);
return TRUE;
}
function commerce_custom_offline_payment_features_rebuild($module) {
return commerce_custom_offline_payment_features_revert($module);
}