From d8fe9408d1ce804f355b5b3004685bf8bf077f1e Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 6 Aug 2013 18:27:39 +0530 Subject: [PATCH] -- fixed for CRM-12970 ---------------------------------------- * CRM-12970: civicrm_price_field_value not removed for discount price set http://issues.civicrm.org/jira/browse/CRM-12970 --- CRM/Event/Form/ManageEvent/Fee.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index ddf017d126..2542f536aa 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -151,7 +151,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $defaults['discounted_label'][$discountFieldsval['weight']] = $discountFieldsval['label']; $defaults['discounted_value'][$discountFieldsval['weight']][$rowCount] = CRM_Utils_Money::format($discountFieldsval['amount'], NULL, '%a'); - $defaults['discount_option_id'][$rowCount][]= $discountFieldsval['id']; + $defaults['discount_option_id'][$rowCount][$discountFieldsval['weight']]= $discountFieldsval['id']; if (CRM_Utils_Array::value('is_default', $discountFieldsval)) { $defaults['discounted_default'] = $discountFieldsval['weight']; } @@ -690,6 +690,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $fieldParams = array(); $params['default_discount_fee_id'] = NULL; $keyCheck = $j-1; + $setParams = array(); if (!CRM_Utils_Array::value($keyCheck, $discountPriceSets)) { if (!$eventTitle) { $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200)); @@ -710,11 +711,17 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_PriceSet::create($setParams); $priceSetID = $priceSet->id; - } else { + } + else { $priceSetID = $discountPriceSets[$j-1]; + $setParams = array ( + 'title' => $params['discount_name'][$j], + 'id' => $priceSetID, + ); if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) { - CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'financial_type_id', $params['financial_type_id']); + $setParams['financial_type_id'] = $params['financial_type_id']; } + CRM_Price_BAO_PriceSet::create($setParams); unset($discountPriceSets[$j-1]); $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id'); } @@ -731,15 +738,15 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { if (CRM_Utils_Array::value('is_default', $value)) { $fieldParams['default_option'] = $value['weight']; } - if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight']-1, $discountFieldIDs[$j])) { - $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']-1]; - unset($discountFieldIDs[$j][$value['weight']-1]); + if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight'], $discountFieldIDs[$j])) { + $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']]; + unset($discountFieldIDs[$j][$value['weight']]); } } //create discount priceset $priceField = CRM_Price_BAO_PriceField::create($fieldParams); - if (!empty($discountFieldIDs)) { - foreach($discountFieldIDs as $fID){ + if (!empty($discountFieldIDs[$j])) { + foreach($discountFieldIDs[$j] as $fID){ CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0'); } } -- 2.25.1