commerce_donate.module in Commerce Donate 7
Module provides donation line item, product and product display node for Drupal Commerce.
File
commerce_donate.moduleView source
<?php
/**
* @file
* Module provides donation line item, product and product display node for
* Drupal Commerce.
*/
/**
* Implements hook_commerce_product_type_info().
*/
function commerce_donate_commerce_product_type_info() {
$items = array(
'donation' => array(
'type' => 'donation',
'name' => 'Donation',
'description' => 'Variable price product',
'help' => '',
'revision' => '1',
'module' => 'commerce_donate',
),
);
return $items;
}
/**
* Implements hook_node_info().
*/
function commerce_donate_node_info() {
$items = array(
'donation' => array(
'name' => t('Donation'),
'base' => 'node_content',
'description' => t('Drupal Commerce donation product'),
'has_title' => '1',
'title_label' => t('Title'),
'help' => '',
),
);
return $items;
}
/**
* Implements hook_commerce_line_item_type_info().
*/
function commerce_donate_commerce_line_item_type_info() {
$line_item_types['commerce_donate'] = array(
'name' => t('Donation'),
'description' => t('Donation line item type'),
'product' => TRUE,
'add_form_submit_value' => t('Add donation'),
'base' => 'commerce_donate_commerce_donate_line_item',
);
return $line_item_types;
}
/**
* Ensures the commerce_donate line item type contains a donation amount field.
*/
function commerce_donate_commerce_donate_line_item_configuration($line_item_type) {
$type = $line_item_type['type'];
commerce_product_line_item_configuration($line_item_type);
// Look for or add a donation amount decimal textfield to the commerce_donate line item type.
$field_name = 'commerce_donate_amount';
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_line_item', $field_name, $type);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'number_decimal',
'cardinality' => 1,
'entity_types' => array(
'commerce_line_item',
),
'translatable' => FALSE,
'locked' => FALSE,
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_line_item',
'bundle' => $type,
'label' => t('Amount'),
'required' => TRUE,
'commerce_cart_settings' => array(
'field_access' => 1,
),
'settings' => array(
'prefix' => '€',
'min' => 1,
),
'widget' => array(
'type' => 'select_or_other_buttons',
'weight' => 0,
'settings' => array(
'available_options' => "5|5.00\n10|10.00\n20|20.00\n50|50.00",
'other' => 'Other amount',
'other_unknown_defaults' => 'other',
),
),
'display' => array(
'display' => array(
'label' => 'hidden',
'weight' => 0,
),
),
'default_value' => array(
0 => array(
'value' => 5,
),
),
);
field_create_instance($instance);
}
}
/**
* Returns a title for this line item.
*/
function commerce_donate_commerce_donate_line_item_title($line_item) {
return commerce_product_line_item_title($line_item);
}
/**
* Implements hook_commerce_checkout_pane_info().
*/
function commerce_donate_commerce_checkout_pane_info() {
$checkout_panes = array();
$checkout_panes['checkout_donate'] = array(
'name' => t('Donation form'),
'title' => check_plain(variable_get('commerce_donate_checkout_pane_title', t('Add a donation'))),
'file' => 'includes/commerce_donate.checkout_pane.inc',
'base' => 'commerce_donate_checkout_pane',
'page' => 'checkout',
'fieldset' => TRUE,
'locked' => FALSE,
'enabled' => FALSE,
);
return $checkout_panes;
}
Functions
Name | Description |
---|---|
commerce_donate_commerce_checkout_pane_info | Implements hook_commerce_checkout_pane_info(). |
commerce_donate_commerce_donate_line_item_configuration | Ensures the commerce_donate line item type contains a donation amount field. |
commerce_donate_commerce_donate_line_item_title | Returns a title for this line item. |
commerce_donate_commerce_line_item_type_info | Implements hook_commerce_line_item_type_info(). |
commerce_donate_commerce_product_type_info | Implements hook_commerce_product_type_info(). |
commerce_donate_node_info | Implements hook_node_info(). |