Commit 4be79955 authored by bgm's avatar bgm Committed by Aegir user

Update cividiscount to v3.5

parent fad0ab9c
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
*/ */
use CRM_CiviDiscount_ExtensionUtil as E;
/** /**
* @package CiviDiscount * @package CiviDiscount
*/ */
...@@ -225,7 +227,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -225,7 +227,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'code' => array( 'code' => array(
'name' => 'code', 'name' => 'code',
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Code'), 'title' => E::ts('Code'),
'required' => TRUE, 'required' => TRUE,
'maxlength' => 255, 'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE, 'size' => CRM_Utils_Type::HUGE,
...@@ -233,7 +235,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -233,7 +235,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'description' => array( 'description' => array(
'name' => 'description', 'name' => 'description',
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Description'), 'title' => E::ts('Description'),
'required' => TRUE, 'required' => TRUE,
'maxlength' => 255, 'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE, 'size' => CRM_Utils_Type::HUGE,
...@@ -241,7 +243,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -241,7 +243,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'filters' => array( 'filters' => array(
'name' => 'filters', 'name' => 'filters',
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Discount Filters'), 'title' => E::ts('Discount Filters'),
'required' => FALSE, 'required' => FALSE,
'maxlength' => 255, 'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE, 'size' => CRM_Utils_Type::HUGE,
...@@ -249,7 +251,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -249,7 +251,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'amount' => array( 'amount' => array(
'name' => 'amount', 'name' => 'amount',
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Amount'), 'title' => E::ts('Amount'),
'required' => TRUE, 'required' => TRUE,
'maxlength' => 255, 'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE, 'size' => CRM_Utils_Type::HUGE,
...@@ -257,7 +259,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -257,7 +259,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'amount_type' => array( 'amount_type' => array(
'name' => 'amount_type', 'name' => 'amount_type',
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Amount Type'), 'title' => E::ts('Amount Type'),
'required' => TRUE, 'required' => TRUE,
'maxlength' => 4, 'maxlength' => 4,
'size' => CRM_Utils_Type::FOUR, 'size' => CRM_Utils_Type::FOUR,
...@@ -265,35 +267,35 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -265,35 +267,35 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'count_max' => array( 'count_max' => array(
'name' => 'count_max', 'name' => 'count_max',
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
'title' => ts('Count Max'), 'title' => E::ts('Count Max'),
'required' => TRUE, 'required' => TRUE,
), ),
'count_use' => array( 'count_use' => array(
'name' => 'count_use', 'name' => 'count_use',
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
'title' => ts('Count Use'), 'title' => E::ts('Count Use'),
'required' => TRUE, 'required' => TRUE,
'default' => 0, 'default' => 0,
), ),
'events' => array( 'events' => array(
'name' => 'events', 'name' => 'events',
'type' => CRM_Utils_Type::T_TEXT, 'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Events'), 'title' => E::ts('Events'),
), ),
'pricesets' => array( 'pricesets' => array(
'name' => 'pricesets', 'name' => 'pricesets',
'type' => CRM_Utils_Type::T_TEXT, 'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Pricesets'), 'title' => E::ts('Pricesets'),
), ),
'memberships' => array( 'memberships' => array(
'name' => 'memberships', 'name' => 'memberships',
'type' => CRM_Utils_Type::T_TEXT, 'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Memberships'), 'title' => E::ts('Memberships'),
), ),
'autodiscount' => array( 'autodiscount' => array(
'name' => 'autodiscount', 'name' => 'autodiscount',
'type' => CRM_Utils_Type::T_TEXT, 'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Autodiscount'), 'title' => E::ts('Autodiscount'),
), ),
'organization_id' => array( 'organization_id' => array(
'name' => 'organization_id', 'name' => 'organization_id',
...@@ -303,12 +305,12 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -303,12 +305,12 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'active_on' => array( 'active_on' => array(
'name' => 'active_on', 'name' => 'active_on',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Activation Date'), 'title' => E::ts('Activation Date'),
), ),
'expire_on' => array( 'expire_on' => array(
'name' => 'expire_on', 'name' => 'expire_on',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Expiration Date'), 'title' => E::ts('Expiration Date'),
), ),
'is_active' => array( 'is_active' => array(
'name' => 'is_active', 'name' => 'is_active',
...@@ -321,7 +323,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO { ...@@ -321,7 +323,7 @@ class CRM_CiviDiscount_DAO_Item extends CRM_Core_DAO {
'discount_msg' => array( 'discount_msg' => array(
'name' => 'discount_msg', 'name' => 'discount_msg',
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Discount Message'), 'title' => E::ts('Discount Message'),
'maxlength' => 255, 'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE, 'size' => CRM_Utils_Type::HUGE,
), ),
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
*/ */
require_once 'CRM/CiviDiscount/DAO/Item.php'; require_once 'CRM/CiviDiscount/DAO/Item.php';
use CRM_CiviDiscount_ExtensionUtil as E;
/** /**
* Page for displaying list of discount codes * Page for displaying list of discount codes
...@@ -63,38 +64,38 @@ class CRM_CiviDiscount_Page_List extends CRM_Core_Page_Basic { ...@@ -63,38 +64,38 @@ class CRM_CiviDiscount_Page_List extends CRM_Core_Page_Basic {
if (!(self::$_links)) { if (!(self::$_links)) {
self::$_links = array( self::$_links = array(
CRM_Core_Action::VIEW => array( CRM_Core_Action::VIEW => array(
'name' => ts('View'), 'name' => E::ts('View'),
'url' => 'civicrm/cividiscount/discount/view', 'url' => 'civicrm/cividiscount/discount/view',
'qs' => 'id=%%id%%&reset=1', 'qs' => 'id=%%id%%&reset=1',
'title' => ts('View Discount Code') 'title' => E::ts('View Discount Code')
), ),
CRM_Core_Action::UPDATE => array( CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'), 'name' => E::ts('Edit'),
'url' => 'civicrm/cividiscount/discount/edit', 'url' => 'civicrm/cividiscount/discount/edit',
'qs' => '&id=%%id%%&reset=1', 'qs' => '&id=%%id%%&reset=1',
'title' => ts('Edit Discount Code') 'title' => E::ts('Edit Discount Code')
), ),
CRM_Core_Action::COPY => array( CRM_Core_Action::COPY => array(
'name' => ts('Copy'), 'name' => E::ts('Copy'),
'url' => 'civicrm/cividiscount/discount/copy', 'url' => 'civicrm/cividiscount/discount/copy',
'qs' => '&cloneID=%%id%%&reset=1', 'qs' => '&cloneID=%%id%%&reset=1',
'title' => ts('Clone Discount Code') 'title' => E::ts('Clone Discount Code')
), ),
CRM_Core_Action::DISABLE => array( CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'), 'name' => E::ts('Disable'),
'class' => 'crm-enable-disable', 'class' => 'crm-enable-disable',
'title' => ts('Disable Discount Code') 'title' => E::ts('Disable Discount Code')
), ),
CRM_Core_Action::ENABLE => array( CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'), 'name' => E::ts('Enable'),
'class' => 'crm-enable-disable', 'class' => 'crm-enable-disable',
'title' => ts('Enable Discount Code') 'title' => E::ts('Enable Discount Code')
), ),
CRM_Core_Action::DELETE => array( CRM_Core_Action::DELETE => array(
'name' => ts('Delete'), 'name' => E::ts('Delete'),
'url' => 'civicrm/cividiscount/discount/delete', 'url' => 'civicrm/cividiscount/discount/delete',
'qs' => '&id=%%id%%', 'qs' => '&id=%%id%%',
'title' => ts('Delete Discount Code') 'title' => E::ts('Delete Discount Code')
) )
); );
} }
...@@ -116,7 +117,7 @@ class CRM_CiviDiscount_Page_List extends CRM_Core_Page_Basic { ...@@ -116,7 +117,7 @@ class CRM_CiviDiscount_Page_List extends CRM_Core_Page_Basic {
* @return string name of this page. * @return string name of this page.
*/ */
function editName() { function editName() {
return ts('Discount Code'); return E::ts('Discount Code');
} }
/** /**
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
*/ */
require_once 'CRM/CiviDiscount/DAO/Item.php'; require_once 'CRM/CiviDiscount/DAO/Item.php';
use CRM_CiviDiscount_ExtensionUtil as E;
/** /**
* Page for displaying discount code details * Page for displaying discount code details
...@@ -70,26 +71,26 @@ class CRM_CiviDiscount_Page_View extends CRM_Core_Page { ...@@ -70,26 +71,26 @@ class CRM_CiviDiscount_Page_View extends CRM_Core_Page {
if (!(self::$_links)) { if (!(self::$_links)) {
self::$_links = array( self::$_links = array(
CRM_Core_Action::UPDATE => array( CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'), 'name' => E::ts('Edit'),
'url' => 'civicrm/cividiscount/discount/edit', 'url' => 'civicrm/cividiscount/discount/edit',
'qs' => '&id=%%id%%&reset=1', 'qs' => '&id=%%id%%&reset=1',
'title' => ts('Edit Discount') 'title' => E::ts('Edit Discount')
), ),
CRM_Core_Action::DISABLE => array( CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'), 'name' => E::ts('Disable'),
'class' => 'crm-enable-disable', 'class' => 'crm-enable-disable',
'title' => ts('Disable Discount') 'title' => E::ts('Disable Discount')
), ),
CRM_Core_Action::ENABLE => array( CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'), 'name' => E::ts('Enable'),
'class' => 'crm-enable-disable', 'class' => 'crm-enable-disable',
'title' => ts('Enable Discount') 'title' => E::ts('Enable Discount')
), ),
CRM_Core_Action::DELETE => array( CRM_Core_Action::DELETE => array(
'name' => ts('Delete'), 'name' => E::ts('Delete'),
'url' => 'civicrm/cividiscount/discount/delete', 'url' => 'civicrm/cividiscount/discount/delete',
'qs' => '&id=%%id%%&reset=1', 'qs' => '&id=%%id%%&reset=1',
'title' => ts('Delete Discount') 'title' => E::ts('Delete Discount')
) )
); );
} }
......
...@@ -56,7 +56,11 @@ function civicrm_api3_discount_code_create($params) { ...@@ -56,7 +56,11 @@ function civicrm_api3_discount_code_create($params) {
*/ */
function _civicrm_api3_discount_code_create_spec(&$params) { function _civicrm_api3_discount_code_create_spec(&$params) {
$params['is_active']['api.default'] = 1; $params['is_active']['api.default'] = 1;
$params['multi_valued']['api.default'] = array(); $params['multi_valued']['api.default'] = array(
'events' => NULL,
'memberships' => NULL,
'pricesets' => NULL,
);
$params['multi_valued']['title'] = 'List of discount types being passed in'; $params['multi_valued']['title'] = 'List of discount types being passed in';
} }
......
<?php <?php
require_once 'cividiscount.civix.php'; require_once 'cividiscount.civix.php';
use CRM_CiviDiscount_ExtensionUtil as E;
/** /**
* Implements hook_civicrm_install(). * Implements hook_civicrm_install().
...@@ -23,15 +24,6 @@ function cividiscount_civicrm_config(&$config) { ...@@ -23,15 +24,6 @@ function cividiscount_civicrm_config(&$config) {
_cividiscount_civix_civicrm_config($config); _cividiscount_civix_civicrm_config($config);
} }
/**
* Implements hook_civicrm_perm().
*
* Module extensions dont implement this hook as yet, will need to add for 4.2
*/
function cividiscount_civicrm_perm() {
return array('view CiviDiscount', 'administer CiviDiscount');
}
/** /**
* Implements hook_civicrm_xmlMenu(). * Implements hook_civicrm_xmlMenu().
*/ */
...@@ -89,7 +81,7 @@ function cividiscount_civicrm_tabs(&$tabs, $cid) { ...@@ -89,7 +81,7 @@ function cividiscount_civicrm_tabs(&$tabs, $cid) {
$tabs[] = array( $tabs[] = array(
'id' => 'discounts', 'id' => 'discounts',
'count' => $count, 'count' => $count,
'title' => ts('Codes Assigned'), 'title' => E::ts('Codes Assigned'),
'weight' => '98', 'weight' => '98',
'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&oid={$cid}", false, null, false), 'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&oid={$cid}", false, null, false),
); );
...@@ -99,7 +91,7 @@ function cividiscount_civicrm_tabs(&$tabs, $cid) { ...@@ -99,7 +91,7 @@ function cividiscount_civicrm_tabs(&$tabs, $cid) {
$tabs[] = array( $tabs[] = array(
'id' => 'discounts', 'id' => 'discounts',
'count' => $count, 'count' => $count,
'title' => ts('Codes Redeemed'), 'title' => E::ts('Codes Redeemed'),
'weight' => '99', 'weight' => '99',
'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&cid={$cid}", false, null, false), 'url' => CRM_Utils_System::url('civicrm/cividiscount/usage', "reset=1&cid={$cid}", false, null, false),
); );
...@@ -238,7 +230,7 @@ function cividiscount_civicrm_validateForm($name, &$fields, &$files, &$form, &$e ...@@ -238,7 +230,7 @@ function cividiscount_civicrm_validateForm($name, &$fields, &$files, &$form, &$e
if ((!$discountInfo || !$discountInfo['autodiscount']) && trim($code) != '') { if ((!$discountInfo || !$discountInfo['autodiscount']) && trim($code) != '') {
if (!$discountInfo) { if (!$discountInfo) {
$errors['discountcode'] = ts('The discount code you entered is invalid.'); $errors['discountcode'] = E::ts('The discount code you entered is invalid.');
return; return;
} }
...@@ -252,7 +244,7 @@ function cividiscount_civicrm_validateForm($name, &$fields, &$files, &$form, &$e ...@@ -252,7 +244,7 @@ function cividiscount_civicrm_validateForm($name, &$fields, &$files, &$form, &$e
$apcount += $sv['additional_participants']; $apcount += $sv['additional_participants'];
} }
if (($discount['count_use'] + $apcount) > $discount['count_max']) { if (($discount['count_use'] + $apcount) > $discount['count_max']) {
$errors['discountcode'] = ts('There are not enough uses remaining for this code.'); $errors['discountcode'] = E::ts('There are not enough uses remaining for this code.');
} }
} }
} }
...@@ -340,7 +332,7 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) { ...@@ -340,7 +332,7 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) {
$discounts = $discountCalculator->getDiscounts(); $discounts = $discountCalculator->getDiscounts();
if (!empty($code) && empty($discounts)) { if (!empty($code) && empty($discounts)) {
$form->set( 'discountCodeErrorMsg', ts('The discount code you entered is invalid.')); $form->set( 'discountCodeErrorMsg', E::ts('The discount code you entered is invalid.'));
} }
// here we check if discount is configured for events or for membership types. // here we check if discount is configured for events or for membership types.
...@@ -419,6 +411,8 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) { ...@@ -419,6 +411,8 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) {
$option['amount'] = $amount; $option['amount'] = $amount;
$option['label'] = $label; $option['label'] = $label;
$option['discount_applied'] = $discountAmount; $option['discount_applied'] = $discountAmount;
$option['discount_code'] = $discount['code'];
$option['discount_description'] = $discount['description'];
/* /*
* Priyanka Karan @ Veda NFP Consulting Ltd * Priyanka Karan @ Veda NFP Consulting Ltd
* Re-calculate VAT/Sales TAX on discounted amount. * Re-calculate VAT/Sales TAX on discounted amount.
...@@ -432,15 +426,19 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) { ...@@ -432,15 +426,19 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) {
} }
} }
} }
$appliedDiscountID = $discountID;
$discountApplied = TRUE; $discountApplied = TRUE;
} }
} }
} }
} }
if ($autodiscount) {
break;
}
} }
// Display discount message if one is available // Display discount message if one is available
if ($pageType == 'event') { if ($pageType == 'event' && !$autodiscount) {
foreach ($discounts as $code => $discount) { foreach ($discounts as $code => $discount) {
if (isset($discount['events']) && array_key_exists($eid, $discount['events']) && if (isset($discount['events']) && array_key_exists($eid, $discount['events']) &&
$discount['discount_msg_enabled'] && (!isset($discountApplied) || !$discountApplied) && !empty($discount['autodiscount'])) { $discount['discount_msg_enabled'] && (!isset($discountApplied) || !$discountApplied) && !empty($discount['autodiscount'])) {
...@@ -449,15 +447,14 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) { ...@@ -449,15 +447,14 @@ function cividiscount_civicrm_buildAmount($pageType, &$form, &$amounts) {
} }
} }
// this seems to incorrectly set to only the last discount but it seems not to matter in the way it is used if (isset($discountApplied) && $discountApplied && !empty($discounts[$appliedDiscountID])) {
if (isset($discountApplied) && $discountApplied) {
if (!empty($ps['fields'])) { if (!empty($ps['fields'])) {
$ps['fields'] = $amounts; $ps['fields'] = $amounts;
$form->setVar('_priceSet', $ps); $form->setVar('_priceSet', $ps);
} }
$form->set('_discountInfo', array( $form->set('_discountInfo', array(
'discount' => $discount, 'discount' => $discounts[$appliedDiscountID],
'autodiscount' => $autodiscount, 'autodiscount' => $autodiscount,
'contact_id' => $contact_id, 'contact_id' => $contact_id,
)); ));
...@@ -497,7 +494,7 @@ function _cividiscount_checkEventDiscountMultipleParticipants($pageType, &$form, ...@@ -497,7 +494,7 @@ function _cividiscount_checkEventDiscountMultipleParticipants($pageType, &$form,
$apcount += $sv['additional_participants']; $apcount += $sv['additional_participants'];
} }
if (($discount['count_use'] + $apcount) > $discount['count_max']) { if (($discount['count_use'] + $apcount) > $discount['count_max']) {
$form->set('discountCodeErrorMsg', ts('There are not enough uses remaining for this code.')); $form->set('discountCodeErrorMsg', E::ts('There are not enough uses remaining for this code.'));
return FALSE; return FALSE;
} }
} }
...@@ -580,11 +577,12 @@ function cividiscount_civicrm_membershipTypeValues(&$form, &$membershipTypeValue ...@@ -580,11 +577,12 @@ function cividiscount_civicrm_membershipTypeValues(&$form, &$membershipTypeValue
$form->set('_discountInfo', NULL); $form->set('_discountInfo', NULL);
$code = CRM_Utils_Request::retrieve('discountcode', 'String', $form, false, null, 'REQUEST'); $code = CRM_Utils_Request::retrieve('discountcode', 'String', $form, false, null, 'REQUEST');
$discountCalculator = new CRM_CiviDiscount_DiscountCalculator('membership_type', NULL, $contact_id, $code, FALSE); $discountCalculator = new CRM_CiviDiscount_DiscountCalculator('membership_type', NULL, $contact_id, $code, FALSE);
if (!empty($code)) { $discounts = $discountCalculator->getDiscounts();
$discounts = $discountCalculator->getDiscounts(); if (empty($code)) {
$discounts = $discountCalculator->autoDiscounts;
} }
if(!empty($code) && empty($discounts)) { if(!empty($code) && empty($discounts)) {
$form->set( 'discountCodeErrorMsg', ts('The discount code you entered is invalid.')); $form->set( 'discountCodeErrorMsg', E::ts('The discount code you entered is invalid.'));
} }
if (empty($discounts)) { if (empty($discounts)) {
return; return;
...@@ -893,7 +891,7 @@ function _cividiscount_filter_membership_discounts($discounts, $membershipTypeVa ...@@ -893,7 +891,7 @@ function _cividiscount_filter_membership_discounts($discounts, $membershipTypeVa
* Calculate either a monetary or percentage discount. * Calculate either a monetary or percentage discount.
*/ */
function _cividiscount_calc_discount($amount, $label, $discount, $autodiscount, $currency = 'USD') { function _cividiscount_calc_discount($amount, $label, $discount, $autodiscount, $currency = 'USD') {
$title = $autodiscount ? ts('Includes automatic member discount of') : ts('Includes applied discount code %1', array(1 => $discount['code'])); $title = $autodiscount ? E::ts('Includes automatic member discount of') : E::ts('Includes applied discount code %1', array(1 => $discount['code']));
if ($discount['amount_type'] == '2') { if ($discount['amount_type'] == '2') {
$newamount = CRM_Utils_Rule::cleanMoney($amount) - CRM_Utils_Rule::cleanMoney($discount['amount']); $newamount = CRM_Utils_Rule::cleanMoney($amount) - CRM_Utils_Rule::cleanMoney($discount['amount']);
$fmt_discount = CRM_Utils_Money::format($discount['amount'], $currency); $fmt_discount = CRM_Utils_Money::format($discount['amount'], $currency);
...@@ -1042,14 +1040,14 @@ function _cividiscount_add_discount_textfield(&$form) { ...@@ -1042,14 +1040,14 @@ function _cividiscount_add_discount_textfield(&$form) {
_cividiscount_add_button_before_priceSet($form); _cividiscount_add_button_before_priceSet($form);
return; return;
} }
$form->addElement('text', 'discountcode', ts('If you have a discount code, enter it here')); $form->addElement('text', 'discountcode', E::ts('If you have a discount code, enter it here'));
$errorMessage = $form->get('discountCodeErrorMsg'); $errorMessage = $form->get('discountCodeErrorMsg');
if ($errorMessage) { if ($errorMessage) {
$form->setElementError('discountcode', $errorMessage); $form->setElementError('discountcode', $errorMessage);
} }
$form->set('discountCodeErrorMsg', null); $form->set('discountCodeErrorMsg', null);
$buttonName = $form->getButtonName('reload'); $buttonName = $form->getButtonName('reload');
$form->addElement('submit', $buttonName, ts('Apply'), array('formnovalidate' => 1)); $form->addElement('submit', $buttonName, E::ts('Apply'), array('formnovalidate' => 1));
$template = CRM_Core_Smarty::singleton(); $template = CRM_Core_Smarty::singleton();
$bhfe = $template->get_template_vars('beginHookFormElements'); $bhfe = $template->get_template_vars('beginHookFormElements');
if (!$bhfe) { if (!$bhfe) {
...@@ -1100,7 +1098,7 @@ function _cividiscount_add_button_before_priceSet(&$form) { ...@@ -1100,7 +1098,7 @@ function _cividiscount_add_button_before_priceSet(&$form) {
$form->add( $form->add(
'text', 'text',
'discountcode', 'discountcode',
ts('If you have a discount code, enter it here'), E::ts('If you have a discount code, enter it here'),
array('class' => 'description') array('class' => 'description')
); );
$errorMessage = $form->get('discountCodeErrorMsg'); $errorMessage = $form->get('discountCodeErrorMsg');
...@@ -1109,7 +1107,7 @@ function _cividiscount_add_button_before_priceSet(&$form) { ...@@ -1109,7 +1107,7 @@ function _cividiscount_add_button_before_priceSet(&$form) {
} }
$form->set('discountCodeErrorMsg', null); $form->set('discountCodeErrorMsg', null);
$buttonName = $form->getButtonName('reload'); $buttonName = $form->getButtonName('reload');
$form->addElement('submit', $buttonName, ts('Apply'), array('formnovalidate' => 1)); $form->addElement('submit', $buttonName, E::ts('Apply'), array('formnovalidate' => 1));
$form->assign('discountElements', array( $form->assign('discountElements', array(
'discountcode', 'discountcode',
$buttonName $buttonName
...@@ -1156,6 +1154,16 @@ function cividiscount_civicrm_navigationMenu( &$params ) { ...@@ -1156,6 +1154,16 @@ function cividiscount_civicrm_navigationMenu( &$params ) {
) )
); );
} }
foreach (array('Events', 'Contributions') as $header) {
_cividiscount_civix_insert_navigation_menu($params, $header, array(
'label' => ts('CiviDiscount', array('domain' => 'org.civicrm.module.cividiscount')),
'name' => 'CiviDiscount',
'url' => 'civicrm/cividiscount',
'permission' => 'administer CiviCRM,administer CiviDiscount',
'operator' => 'OR',
'separator' => 2,
));
}
} }
/** /**
...@@ -1174,3 +1182,9 @@ function cividiscount_civicrm_entityTypes(&$entityTypes) { ...@@ -1174,3 +1182,9 @@ function cividiscount_civicrm_entityTypes(&$entityTypes) {
); );
} }
function cividiscount_civicrm_permission(&$permissions) {
$permissions += array(
'administer CiviDiscount' => ts('administer CiviDiscount', array('domain' => 'org.civicrm.module.cividiscount')),
);
}
# Automatic discounts
Anyone with the selected memberships or contact attributes will automatically have the discount code applied provided they are logged in to the website. Autodiscount is generally used with a randomly-generated code which is not given out to users. Cividiscount will apply the discount with no code required.
![Screenshot of automatic discount setup](/images/autodiscount.png)
* Automatic discounts can be applied based on membership status and/or type.
* Automatic discounts can be applied to contacts based on type, age (minimum or maximum) and/or country
### Advanced Filters
CiviDiscount now allows you to specify your own criteria for who should get automatic discounts. This is a powerful feature but does require some technical skill and thorough testing is recommended. Use the api explorer (on your site at the url civicrm/api/explorer) to help you discover the api options you could pass.
You need to specify an API Entity that you want to query and a query string. If you specify contact then the logged in contact id will be passed in as 'id'. For all other api it will be passed in as 'contact_id'
In this image you can see that contacts with a value of 1 in custom id field 65 (which happens to be 'are you retired' in this case) will get an automatic discount if they meet other criteria above - ie a minimum age of 65)
![Screenshot of advanced filter example](/images/advancedFilters.jpg)
# Setup discount codes
Under **Administer > CiviDiscount** click **New Discount Code.**
![Screenshot of discount code setup](/images/codesetup.png)
**Discount Code:** Create a custom code or click the random code button. Codes can only consist of alphanumeric characters.