View source
<?php
define('BASIC_CART_DEFAULT_CURRENCY', 'USD');
define('BASIC_CART_VAT_STATE', FALSE);
define('BASIC_CART_VAT_VALUE', '');
function basic_cart_install() {
$t = get_t();
variable_set('basic_cart_currency', BASIC_CART_DEFAULT_CURRENCY);
variable_set('basic_cart_admin_subject', $t('New order placed'));
$default_admin_message = $t('Hi,
An order was placed by [node:title] ([node:field_email]
Ordered products:
[basic_cart_order:products]
Total price: [node:field_total_price]');
variable_set('basic_cart_admin_message', $default_admin_message);
variable_set('basic_cart_send_user_message', 1);
variable_set('basic_cart_user_subject', $t('New order placed'));
$default_user_message = $t('Hi,
You just placed an order on the website @sitename. Here are the order details:
[basic_cart_order:products]
Total price: [node:field_total_price]
We will contact you as soon as possible.', array(
'@sitename' => variable_get('site_name'),
));
variable_set('basic_cart_user_message', $default_user_message);
$default_thank_you_title = $t("Thank you.");
variable_set('basic_cart_thank_you_title', $default_thank_you_title);
$default_thank_you_message = $t("Thank you for placing an order on our website.\nWe will contact you as soon as possible.");
variable_set('basic_cart_thank_you_message', $default_thank_you_message);
variable_set('basic_cart_redirect_user_after_add_to_cart', '<none>');
foreach (basic_cart_get_fields() as $field_name => $field_) {
$field = field_info_field($field_name);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => $field_['type'],
'entity_types' => array(
'node',
),
);
field_create_field($field);
}
}
variable_set('basic_cart_vat_state', BASIC_CART_VAT_STATE);
variable_set('basic_cart_vat_value', BASIC_CART_VAT_VALUE);
}
function basic_cart_uninstall() {
variable_del('basic_cart_currency');
$types = variable_get('basic_cart_content_types');
if (is_array($types)) {
drupal_load('module', 'basic_cart');
foreach ($types as $type => $checked) {
if (!empty($checked)) {
foreach (basic_cart_get_fields() as $field_name => $field_) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $type,
);
field_delete_instance($instance);
}
}
}
}
variable_del('basic_cart_content_types');
variable_del('basic_cart_admin_subject');
variable_del('basic_cart_admin_message');
variable_del('basic_cart_user_subject');
variable_del('basic_cart_user_message');
variable_del('basic_cart_send_user_message');
variable_del('basic_cart_thank_you_title');
variable_del('basic_cart_thank_you_message');
variable_del('basic_cart_redirect_user_after_add_to_cart');
variable_del('basic_cart_vat_state');
variable_del('basic_cart_vat_value');
}
function basic_cart_update_7200() {
variable_set('basic_cart_currency', BASIC_CART_DEFAULT_CURRENCY);
$field = field_info_field('price');
if (empty($field)) {
$field = array(
'field_name' => 'price',
'type' => 'number_decimal',
'entity_types' => array(
'node',
),
);
field_create_field($field);
}
$node_types = variable_get('basic_cart_content_types');
if (is_array($node_types)) {
foreach ($node_types as $type => $checked) {
if ($checked) {
$instance = field_info_instance('node', 'price', $type);
if (empty($instance)) {
$instance = array(
'field_name' => 'price',
'label' => t('Price'),
'description' => t('Please enter the price for this item.'),
'entity_type' => 'node',
'bundle' => $type,
);
field_create_instance($instance);
}
}
else {
$instance = field_info_instance('node', 'price', $type);
if (!empty($instance)) {
field_delete_instance($instance);
}
}
}
}
}
function basic_cart_update_7201() {
$product_types = basic_cart_product_types();
if (!empty($product_types)) {
$backup_products = array();
foreach ($product_types as $product_type => $is_active) {
if (!empty($is_active)) {
$query = db_select('node', 'n')
->fields('n', array(
'nid',
));
$products = $query
->condition('type', $product_type, '=')
->execute()
->fetchAll();
if (!empty($products) && is_array($products)) {
foreach ($products as $i => $node) {
$node = node_load($node->nid);
$backup_products[$product_type][$node->nid] = $node;
}
}
}
}
field_delete_field('price');
field_purge_batch(10);
$field = array(
'field_name' => 'price',
'type' => 'number_decimal',
'entity_types' => array(
'node',
),
);
field_create_field($field);
if (!empty($backup_products)) {
foreach ($backup_products as $product_type => $nodes) {
$instance = array(
'field_name' => 'price',
'label' => t('Price'),
'description' => t('Please enter the price for this item.'),
'entity_type' => 'node',
'bundle' => $product_type,
);
field_create_instance($instance);
foreach ($nodes as $nid => $node) {
node_save($node);
}
}
}
}
variable_set('basic_cart_redirect_user_after_add_to_cart', '<none>');
variable_set('basic_cart_vat_state', BASIC_CART_VAT_STATE);
variable_set('basic_cart_vat_value', BASIC_CART_VAT_VALUE);
}
function basic_cart_update_7202() {
foreach (basic_cart_get_fields() as $field_name => $field_) {
$field = field_info_field($field_name);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => $field_['type'],
'entity_types' => array(
'node',
),
);
field_create_field($field);
}
}
$content_types = basic_cart_product_types();
if (!empty($content_types) && is_array($content_types)) {
foreach ($content_types as $type => $checked) {
if ($checked) {
$product_types[$type] = $type;
foreach (basic_cart_get_fields() as $field_name => $field_) {
$instance = field_info_instance('node', $field_name, $type);
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'label' => $field_['title'],
'description' => $field_['description'],
'entity_type' => 'node',
'bundle' => $type,
);
field_create_instance($instance);
}
}
}
else {
foreach (basic_cart_get_fields() as $field_name => $field_) {
$instance = field_info_instance('node', $field_name, $type);
if (!empty($instance)) {
field_delete_instance($instance);
}
}
}
}
}
}