function commerce_gc_product_example_modules_enabled in Commerce GC 7
File
- modules/
commerce_gc_product_example/ commerce_gc_product_example.module, line 12
Code
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();
// Create the new product.
$product = commerce_product_new('giftcard');
$product->sku = 'giftcard-1';
$product->title = 'Giftcard 1';
$product->language = LANGUAGE_NONE;
$product->uid = 1;
// Set a default price.
$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;
// Save it.
commerce_product_save($product);
// Create a sample product and node display
$node = (object) array(
'type' => 'giftcard_product_display',
);
node_object_prepare($node);
$node->title = $product->title;
$node->uid = 1;
// Reference the product we just made.
// $node->field_product[LANGUAGE_NONE][]['product_id'] = $product->product_id;
$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->field_product[] = $product->product_id;
// Make sure we set the default language
$node->language = LANGUAGE_NONE;
// Save it and retain a copy.
node_save($node);
variable_set('commerce_gc_product_example_added_content', TRUE);
}
}