View source
<?php
function commerce_kickstart_form_install_configure_form_alter(&$form, $form_state) {
$form['site_information']['site_name']['#default_value'] = t('Commerce Kickstart');
$form['server_settings']['site_default_country']['#default_value'] = 'US';
}
function commerce_kickstart_install_tasks() {
$tasks = array();
$tasks['commerce_kickstart_example_store_form'] = array(
'display_name' => st('Example store'),
'type' => 'form',
);
return $tasks;
}
function commerce_kickstart_example_store_form() {
drupal_set_title(st('Example store content'));
$options = array(
'products' => st('Products'),
'product_displays' => st('Product display nodes (if <em>Products</em> is selected)'),
);
$form['example_content'] = array(
'#type' => 'checkboxes',
'#title' => st('Create example content for the following store components:'),
'#description' => st('The example content is not comprehensive but illustrates how the basic components work.'),
'#options' => $options,
'#default_value' => drupal_map_assoc(array_keys($options)),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Create and continue'),
'#weight' => 15,
);
return $form;
}
function commerce_kickstart_example_store_form_submit(&$form, &$form_state) {
$example_content = $form_state['values']['example_content'];
$created_products = array();
$created_nodes = array();
if (!empty($example_content['products'])) {
$product_names = array(
'01' => st('Product One'),
'02' => st('Product Two'),
'03' => st('Product Three'),
);
foreach ($product_names as $sku => $title) {
$product = commerce_product_new('product');
$product->sku = 'PROD-' . $sku;
$product->title = $title;
$product->language = LANGUAGE_NONE;
$product->uid = 1;
$product->commerce_price[LANGUAGE_NONE][0]['amount'] = $sku * 1000;
$product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
commerce_product_save($product);
$created_products[] = $product;
if (!empty($example_content['product_displays'])) {
$node = (object) array(
'type' => 'product_display',
);
node_object_prepare($node);
$node->title = $product->title;
$node->uid = 1;
$node->field_product[LANGUAGE_NONE][]['product_id'] = $product->product_id;
$node->language = LANGUAGE_NONE;
node_save($node);
$created_nodes[] = $node;
}
}
}
}
function _commerce_kickstart_create_example_catalog() {
$description = st('Describes a hierarchy for the product catalog.');
$vocabulary = (object) array(
'name' => st('Catalog'),
'description' => $description,
'machine_name' => 'catalog',
'help' => '',
);
taxonomy_vocabulary_save($vocabulary);
$field = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$instance = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'entity_type' => 'node',
'label' => st('Catalog category'),
'bundle' => 'product_display',
'description' => '',
'widget' => array(
'type' => 'options_select',
),
);
field_create_instance($instance);
}
function _commerce_kickstart_create_product_image_field($entity_type, $bundle) {
$instance = array(
'field_name' => 'field_image',
'entity_type' => $entity_type,
'label' => st('Image'),
'bundle' => $bundle,
'description' => st('Upload an image for this product.'),
'required' => FALSE,
'settings' => array(
'file_directory' => 'field/image',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '',
'max_resolution' => '',
'min_resolution' => '',
'alt_field' => TRUE,
'title_field' => '',
),
'widget' => array(
'type' => 'image_image',
'settings' => array(
'progress_indicator' => 'throbber',
'preview_image_style' => 'thumbnail',
),
'weight' => -1,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'medium',
'image_link' => 'file',
),
'weight' => -1,
),
'full' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'medium',
'image_link' => 'file',
),
'weight' => -1,
),
'line_item' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'thumbnail',
'image_link' => '',
),
'weight' => -1,
),
'node_full' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'medium',
'image_link' => 'file',
),
'weight' => -1,
),
'node_teaser' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'thumbnail',
'image_link' => 'content',
),
'weight' => -1,
),
'node_rss' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'medium',
'image_link' => '',
),
'weight' => -1,
),
),
);
field_create_instance($instance);
}
function _commerce_kickstart_create_product_reference($entity_type, $bundle, $field_name = 'field_product') {
$field = array(
'field_name' => $field_name,
'type' => 'commerce_product_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
);
field_create_field($field);
$instance = array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'label' => st('Product'),
'bundle' => $bundle,
'description' => st('Choose the product(s) to display for sale on this node by SKU. Enter multiple SKUs using a comma separated list.'),
'required' => TRUE,
'widget' => array(
'type' => 'commerce_product_reference_autocomplete',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
'full' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
),
);
field_create_instance($instance);
}
function commerce_kickstart_update_projects_alter(&$projects) {
$modules = system_rebuild_module_data();
$kickstart = clone $modules['commerce_kickstart'];
$kickstart->info['hidden'] = FALSE;
_update_process_info_list($projects, array(
'commerce_kickstart' => $kickstart,
), 'module', TRUE);
}
function commerce_kickstart_update_status_alter(&$projects) {
$distribution_secure = !in_array($projects['commerce_kickstart']['status'], array(
UPDATE_NOT_SECURE,
UPDATE_REVOKED,
UPDATE_NOT_SUPPORTED,
));
$make_filepath = drupal_get_path('module', 'commerce_kickstart') . '/drupal-org.make';
if (!file_exists($make_filepath)) {
return;
}
$make_info = drupal_parse_info_file($make_filepath);
foreach ($projects as $project_name => $project_info) {
if (!isset($project_info['info']['version']) || !isset($make_info['projects'][$project_name])) {
continue;
}
if ($distribution_secure && in_array($project_info['status'], array(
UPDATE_NOT_SECURE,
UPDATE_REVOKED,
UPDATE_NOT_SUPPORTED,
))) {
continue;
}
$make_project_version = is_array($make_info['projects'][$project_name]) ? $make_info['projects'][$project_name]['version'] : $make_info['projects'][$project_name];
if (DRUPAL_CORE_COMPATIBILITY . '-' . $make_project_version == $project_info['info']['version']) {
$projects['commerce_kickstart']['includes'][$project_info['name']] = $project_info['info']['name'];
unset($projects[$project_name]);
}
}
}