Commit f5637cd5 authored by lobo's avatar lobo
Browse files

Merge pull request #36 from rajeshrhino/master

Fix for issue: Discount code which is only set to apply to certain price...
parents 515d3161 d4d1b35e
...@@ -393,50 +393,52 @@ function cividiscount_civicrm_buildAmount($pagetype, &$form, &$amounts) { ...@@ -393,50 +393,52 @@ function cividiscount_civicrm_buildAmount($pagetype, &$form, &$amounts) {
// as $discounts[$key]['pricesets'] from _cividiscount_get_candidate_discounts(); above // as $discounts[$key]['pricesets'] from _cividiscount_get_candidate_discounts(); above
} }
else { else {
$discounts[$key]['pricesets'] = array(); if (empty($discounts[$key]['pricesets'])) {
// filter only valid membership types that have discount $discounts[$key]['pricesets'] = array();
foreach( $priceSetInfo as $pfID => $priceFieldValues ) { // filter only valid membership types that have discount
if ( !empty($priceFieldValues['membership_type_id']) && foreach( $priceSetInfo as $pfID => $priceFieldValues ) {
in_array($priceFieldValues['membership_type_id'], $discounts[$key]['memberships'])) { if ( !empty($priceFieldValues['membership_type_id']) &&
$discounts[$key]['pricesets'][$pfID] = $pfID; in_array($priceFieldValues['membership_type_id'], $discounts[$key]['memberships'])) {
$discounts[$key]['pricesets'][$pfID] = $pfID;
}
} }
} }
} }
$discount = array_shift($discounts); //$discount = array_shift($discounts);
foreach ($discounts as $done_care => $discount) {
// we need a extra check to make sure discount is valid for additional participants // we need a extra check to make sure discount is valid for additional participants
// check the max usage and existing usage of discount code // check the max usage and existing usage of discount code
if ($pagetype == 'event' && _cividiscount_allow_multiple()) { if ($pagetype == 'event' && _cividiscount_allow_multiple()) {
if ($discount['count_max'] > 0) { if ($discount['count_max'] > 0) {
// Initially 1 for person registering. // Initially 1 for person registering.
$apcount = 1; $apcount = 1;
$sv = $form->getVar('_submitValues'); $sv = $form->getVar('_submitValues');
if (array_key_exists('additional_participants', $sv)) { if (array_key_exists('additional_participants', $sv)) {
$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', ts('There are not enough uses remaining for this code.'));
return; return;
}
} }
} }
} foreach ($amounts as &$fee) {
if (!is_array($fee['options'])) {
foreach ($amounts as &$fee) { continue;
if (!is_array($fee['options'])) { }
continue;
}
foreach ($fee['options'] as &$option) { foreach ($fee['options'] as &$option) {
if (CRM_Utils_Array::value($option['id'], $discount['pricesets'])) { if (CRM_Utils_Array::value($option['id'], $discount['pricesets'])) {
list($option['amount'], $option['label']) = list($option['amount'], $option['label']) =
_cividiscount_calc_discount($option['amount'], $option['label'], $discount, $autodiscount, $currency); _cividiscount_calc_discount($option['amount'], $option['label'], $discount, $autodiscount, $currency);
}
} }
} }
} }
} }
$form->set('_discountInfo', array( $form->set('_discountInfo', array(
......
Supports Markdown
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