commerce_userpoints.module in Commerce userpoints 7
Hook implementations and API functions for the commerce_userpoints module.
File
commerce_userpoints.moduleView source
<?php
/**
* @file
* Hook implementations and API functions for the commerce_userpoints module.
*/
/**
* Implements hook_help().
*/
function commerce_userpoints_help($path) {
$help = '';
switch ($path) {
case 'admin/commerce/config/currency/userpoints':
$help = t('This page allows to set up a virtual currency for each !points category. After this, it can for example be used to buy products with these !points.', userpoints_translation());
break;
}
return $help;
}
/**
* Implements hook_permission().
*/
function commerce_userpoints_permission() {
return array(
'admin commerce userpoints' => array(
'title' => t('admin commerce userpoints'),
'description' => t('admin commerce userpoints'),
),
);
}
/**
* Implements hook_menu().
*/
function commerce_userpoints_menu() {
$items = array();
$items['admin/commerce/config/currency/default'] = array(
'title' => 'Currency settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/commerce/config/currency/userpoints'] = array(
'title' => '!Points currencies',
'title arguments' => userpoints_translation(),
'page callback' => 'commerce_userpoints_currencies_page',
'access arguments' => array(
'configure store',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'commerce_userpoints.admin.inc',
);
$items['admin/commerce/config/currency/userpoints/add'] = array(
'title' => 'Add a !points currency',
'title arguments' => userpoints_translation(),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'commerce_userpoints_currencies_form',
),
'access arguments' => array(
'configure store',
),
'type' => MENU_LOCAL_ACTION,
'file' => 'commerce_userpoints.admin.inc',
);
$items['admin/commerce/config/currency/userpoints/edit/%commerce_userpoints'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'commerce_userpoints_currencies_form',
6,
),
'access arguments' => array(
'configure store',
),
'type' => MENU_LOCAL_TASK,
'file' => 'commerce_userpoints.admin.inc',
);
$items['admin/commerce/config/currency/userpoints/delete/%commerce_userpoints'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'commerce_userpoints_currencies_delete',
6,
),
'access arguments' => array(
'configure store',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'commerce_userpoints.admin.inc',
);
return $items;
}
/**
* Returns the currently configured userpoints currencies.
*
* @return
* An array of userpoints categories
*/
function commerce_userpoints_currencies() {
return variable_get('commerce_userpoints_currencies', array());
}
/**
* @return
* An array of userpoints categories that used as currency.
*/
function commerce_userpoints_currencies_option_list() {
$userpoint_currencies = commerce_userpoints_currencies();
if (!empty($userpoint_currencies)) {
$options = array();
foreach ($userpoint_currencies as $key => $val) {
$options[$key] = $val['name'];
}
return $options;
}
return FALSE;
}
/**
* Load a userpoints currency based on the code.
*/
function commerce_userpoints_load($code) {
$currencies = commerce_userpoints_currencies();
if (isset($currencies[$code])) {
return $currencies[$code];
}
return FALSE;
}
/**
* Implements hook_commerce_currency_info().
*/
function commerce_userpoints_commerce_currency_info() {
$currencies = array();
$default_currency = commerce_default_currency();
foreach (commerce_userpoints_currencies() as $currency) {
$currencies[$currency['code']] = array(
'code' => $currency['code'],
'symbol' => $currency['symbol'],
'name' => $currency['name'],
'rounding_step' => '1',
// Userpoints currently does not support decimals.
'decimals' => 0,
'conversion_rate' => !empty($currency['conversion_rate']) ? $currency['conversion_rate'] : 0.01,
);
}
return $currencies;
}
/**
* Implements hook_theme().
* cu_points is short of commerce_userpoints_points.
*/
function commerce_userpoints_theme() {
return array(
'cu_points' => array(
'variables' => array(
$points = NULL,
),
),
);
}
function theme_cu_points($vars) {
return '<span class="commerce_userpoints-points">' . $vars['points'] . '</span>';
}
Functions
Name![]() |
Description |
---|---|
commerce_userpoints_commerce_currency_info | Implements hook_commerce_currency_info(). |
commerce_userpoints_currencies | Returns the currently configured userpoints currencies. |
commerce_userpoints_currencies_option_list | |
commerce_userpoints_help | Implements hook_help(). |
commerce_userpoints_load | Load a userpoints currency based on the code. |
commerce_userpoints_menu | Implements hook_menu(). |
commerce_userpoints_permission | Implements hook_permission(). |
commerce_userpoints_theme | Implements hook_theme(). cu_points is short of commerce_userpoints_points. |
theme_cu_points |