commerce_gc_product_example.module in Commerce GC 7
File
modules/commerce_gc_product_example/commerce_gc_product_example.module
View source
<?php
include_once 'commerce_gc_product_example.features.inc';
function commerce_gc_product_example_modules_enabled($modules) {
if (in_array('commerce_gc_product_example', $modules) && !variable_get('commerce_gc_product_example_added_content')) {
_commerce_gc_product_example_ensure_config();
field_info_cache_clear();
$product = commerce_product_new('giftcard');
$product->sku = 'giftcard-1';
$product->title = 'Giftcard 1';
$product->language = LANGUAGE_NONE;
$product->uid = 1;
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
$price = array(
'amount' => 1000,
'currency_code' => 'USD',
);
$product_wrapper->commerce_gc_value = $price;
$product_wrapper->commerce_price = $price;
commerce_product_save($product);
$node = (object) array(
'type' => 'giftcard_product_display',
);
node_object_prepare($node);
$node->title = $product->title;
$node->uid = 1;
$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->field_product[] = $product->product_id;
$node->language = LANGUAGE_NONE;
node_save($node);
variable_set('commerce_gc_product_example_added_content', TRUE);
}
}
function _commerce_gc_product_example_ensure_config() {
$module = 'commerce_gc_product_example';
$feature = features_load_feature($module, TRUE);
$items[$module] = array_keys($feature->info['features']);
features_include_defaults(NULL, TRUE);
_features_restore('enable', $items);
features_include(TRUE);
$all_components = array_keys(features_get_components());
foreach ($items as $module => $components) {
$items[$module] = array_intersect($all_components, $components);
}
_features_restore('rebuild', $items);
commerce_product_configure_product_type('giftcard');
}