Commit 17cbc2ba authored by rfay's avatar rfay

Add a line item example:

parent 3bd352c7
name = Line Item Example
description = Demonstrates Line Item APIs for Commerce, including adding custom line items
package = Commerce (contrib)
dependencies[] = commerce_line_item
core = 7.x
<?php
/**
* @file line_item_example.module
* Demonstrates the addition of a new pane to the checkout system.
*/
/**
* Implements hook_menu().
*
* Simply presents a page that will explain what this module is for.
* hook_menu() has nothing to do with the checkout pane functionality.
*/
function line_item_example_menu() {
$items['commerce_examples/line_item_example'] = array(
'title' => 'Line Item Example',
'page callback' => 'line_item_example_info_page',
'access callback' => TRUE,
);
return $items;
}
/**
* This function simply returns information about the example to help the
* user understand its purpose.
*/
function line_item_example_info_page() {
return array(
'#markup' => t('The line item example demonstrates adding a custom line item and also how to use related API functions. With this module enabled, an additional line item may be selected by add-to-cart forms.'),
);
}
/**
* Implements hook_enable() to provide a new line item type.
*/
function line_item_example_enable() {
// Here we'll use commerce_product_line_item_configuration(), which adds the
// 'commerce_product' field to the line item. If we didn't need that field,
// we could do less.
commerce_product_line_item_configuration('example_line_item');
}
/**
* Implements hook_commerce_line_item_type_info().
*
* @see hook_commerce_line_item_type_info().
*
*/
function line_item_example_commerce_line_item_type_info() {
$line_item_types['example_line_item'] = array(
'name' => t('Example Line Item'),
'description' => t('Example Line Item type of line item'),
'product' => TRUE,
// Here you can change the text in the submit button in the add to cart form
'add_form_submit_value' => t('Add product'),
'base' => 'commerce_product_line_item',
);
return $line_item_types;
}
/**
* Implements hook_commerce_line_item_type_info_alter() to change the standard
* 'product' line item type's 'add_form_submit_value'.
* Note that this only runs when the cache is cleared.
*
* @see hook_commerce_line_item_type_info_alter().
*
* @param $line_item_types
* The array of types to be altered
*/
function line_item_example_commerce_line_item_type_info_alter(&$line_item_types) {
if (!empty($line_item_types['product'])) {
$line_item_types['product']['name'] = t('Widgets');
// The add_form_submit_value is only used on the order page.
$line_item_types['product']['add_form_submit_value'] = t('Buy it now!');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment