CRM-17397 fix enotices on amount_level
authoreileenmcnaugton <eileen@fuzion.co.nz>
Thu, 22 Oct 2015 23:07:28 +0000 (12:07 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Thu, 22 Oct 2015 23:07:28 +0000 (12:07 +1300)
After looking at this I think the 'right' answer is to always go to the same function to find out what the amount_level
should be - rather than calculate it on the forms and / or tack it onto the function that derives the line_items

I made this change on the form that was experiencing an issue & added a test.

Elsewhere I just added comments

15 files changed:
CRM/Batch/Form/Entry.php
CRM/Contribute/Form/AdditionalPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php
CRM/Event/Cart/Form/Checkout/Payment.php
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/AdditionalParticipant.php
CRM/Event/Form/Registration/Register.php
CRM/Price/BAO/PriceSet.php
CRM/Utils/Cache.php
tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php
tests/phpunit/CRM/Price/BAO/PriceSetTest.php [new file with mode: 0644]
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 68dafe06c2d657abbe34ee8ce9cb323bda882057..a5a023d75459dc9ae411dae335e3f2521e449261 100755 (executable)
@@ -506,12 +506,18 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
         $lineItem = array();
         CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
 
-        //unset amount level since we always use quick config price set
+        // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+        // function to get correct amount level consistently. Remove setting of the amount level in
+        // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+        // to cover all variants.
         unset($value['amount_level']);
 
         //CRM-11529 for back office transactions
         //when financial_type_id is passed in form, update the
         //line items with the financial type selected in form
+        // @todo - create a price set or price field per financial type & simply choose the appropriate
+        // price field rather than working around the fact that each price_field is supposed to have a financial
+        // type & we are allowing that to be overridden.
         if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
           foreach ($lineItem[$priceSetId] as &$values) {
             $values['financial_type_id'] = $value['financial_type_id'];
index e802fd2f11540e7511008e1a75dd299009ae9d22..49bd5e98a03c9d6a6ad58e6d7280a6493506c9e5 100644 (file)
@@ -484,6 +484,10 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     }
     $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
     $this->_params['amount'] = $this->_params['total_amount'];
+    // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+    // function to get correct amount level consistently. Remove setting of the amount level in
+    // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+    // to cover all variants.
     $this->_params['amount_level'] = 0;
     $this->_params['currencyID'] = CRM_Utils_Array::value('currency',
       $this->_params,
index 7b00a75e11592bc03b2937885b108173cca75f6c..b742655b0936176a8a335623686158793b08bbd5 100644 (file)
@@ -1096,6 +1096,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     $this->_params['amount'] = $this->_params['total_amount'];
+    // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+    // function to get correct amount level consistently. Remove setting of the amount level in
+    // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+    // to cover all variants.
     $this->_params['amount_level'] = 0;
     $this->_params['description'] = ts("Contribution submitted by a staff person using contributor's credit card");
     $this->_params['currencyID'] = CRM_Utils_Array::value('currency',
index db2bf893c8d737b9e23c3b53cc6c1964032f4025..e0a9f952798b4c18502d41e4e6e2610daa61107d 100644 (file)
@@ -1762,6 +1762,10 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       }
       if ($isQuickConfig && !empty($this->_params["price_{$priceField->id}"])) {
         if ($this->_values['fee'][$priceField->id]['html_type'] != 'Text') {
+          // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+          // function to get correct amount level consistently. Remove setting of the amount level in
+          // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+          // to cover all variants.
           $this->_params['amount_level'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue',
             $this->_params["price_{$priceField->id}"], 'label');
         }
index 735544f20fd6549f1d1a70fefe0eb7a500494c22..d03eb0557a6f564be3cc0f54e76175c7a5a655b3 100644 (file)
@@ -951,6 +951,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
         $amountID = CRM_Utils_Array::value('amount', $params);
 
         if ($amountID) {
+          // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+          // function to get correct amount level consistently. Remove setting of the amount level in
+          // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+          // to cover all variants.
           $params['amount_level'] = CRM_Utils_Array::value('label', $formValues[$amountID]);
           $amount = CRM_Utils_Array::value('value', $formValues[$amountID]);
         }
index 2da894c39fa6d87e5f9683bcb2dc40b09c477825..1f11cabdea2df344975bd2aceae02b7e2d177723 100644 (file)
@@ -511,6 +511,10 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
       ));
     }
 
+    // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+    // function to get correct amount level consistently. Remove setting of the amount level in
+    // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+    // to cover all variants.
     if (isset($this->_params['amount_other']) || isset($this->_params['selectMembership'])) {
       $this->_params['amount_level'] = '';
     }
index bbbac759d94f2750ab7c6047ce913d9bfd181dca..4a61f11a245dd973078ffeb47d1ae3e02bb18618 100644 (file)
@@ -254,6 +254,10 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart {
       $price_set_amount = array();
       CRM_Price_BAO_PriceSet::processAmount($price_set['fields'], $event_price_values, $price_set_amount);
       $cost = $event_price_values['amount'];
+      // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
+      // function to get correct amount level consistently. Remove setting of the amount level in
+      // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
+      // to cover all variants.
       $amount_level = $event_price_values['amount_level'];
       $price_details[$price_set_id] = $price_set_amount;
     }
index 3f858c76832d292f193920b695d7b2bce6f8a263..c7a204978070459d88513f58dfcf9f94de969dae 100644 (file)
@@ -1499,4 +1499,23 @@ WHERE  v.option_group_id = g.id
     }
   }
 
+  /**
+   * Get the amount level for the event payment.
+   *
+   * The amount level is the string stored on the contribution record that describes the purchase.
+   *
+   * @param array $params
+   * @param int|null $discountID
+   *
+   * @return string
+   */
+  protected function getAmountLevel($params, $discountID) {
+    // @todo move handling of discount ID to the BAO function - preferably by converting it to a price_set with
+    // time settings.
+    if (!empty($this->_values['discount'][$discountID])) {
+      return $this->_values['discount'][$discountID][$params['amount']]['label'];
+    }
+    return CRM_Price_BAO_PriceSet::getAmountLevelText($params);
+  }
+
 }
index 9aadd5978d74c65846d205af08e56ff16995a9ed..2a639c172a28161cf4720c1da32e370e58921538 100644 (file)
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
  */
 
 /**
- * This class generates form components for processing Event
- *
+ * This class generates form components for processing Event.
  */
 class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_Registration {
 
@@ -662,14 +659,12 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R
 
         //added for discount
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
-
+        $params['amount_level'] = $this->getAmountLevel($params, $discountId);
         if (!empty($this->_values['discount'][$discountId])) {
           $params['discount_id'] = $discountId;
-          $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
           $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
         }
         elseif (empty($params['priceSetId'])) {
-          $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
           $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
         }
         else {
index 988190f01c4f13d194ba616008cf42fa1c5921bb..498e1b3dde087331e1a6350db6d17c5c2766ec3a 100644 (file)
@@ -1024,20 +1024,17 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
 
       //added for discount
       $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
-
+      $params['amount_level'] = $this->getAmountLevel($params, $discountId);
       if (!empty($this->_values['discount'][$discountId])) {
         $params['discount_id'] = $discountId;
-        $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
-
         $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
       }
       elseif (empty($params['priceSetId'])) {
         if (!empty($params['amount'])) {
-          $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
           $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
         }
         else {
-          $params['amount_level'] = $params['amount'] = '';
+          $params['amount'] = '';
         }
       }
       else {
index 25429bae885fd977804e90c59ebfc6705da4ff4d..27c979e75309c392af23a13a5af97fce3a8149d4 100644 (file)
@@ -904,6 +904,7 @@ WHERE  id = %1";
         // But, in the interests of being careful when capacity is low - avoiding the known default value
         // will get us by.
         // Crucially a test has been added so a better solution can be implemented later with some comfort.
+        // @todo - stop setting amount level in this function & call the getAmountLevel function to retrieve it.
         if ($values['label'] != ts('Contribution Amount')) {
           $amount_level[] = $values['label'] . ' - ' . (float) $values['qty'];
         }
@@ -914,6 +915,7 @@ WHERE  id = %1";
     if ($totalParticipant > 0) {
       $displayParticipantCount = ' Participant Count -' . $totalParticipant;
     }
+    // @todo - stop setting amount level in this function & call the getAmountLevel function to retrieve it.
     if (!empty($amount_level) && !empty($displayParticipantCount)) {
       $params['amount_level'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $amount_level) . $displayParticipantCount . CRM_Core_DAO::VALUE_SEPARATOR;
     }
@@ -931,6 +933,89 @@ WHERE  id = %1";
     }
   }
 
+  /**
+   * Get the text to record for amount level.
+   *
+   * @param array $params
+   *   Submitted parameters
+   *   - priceSetId is required to be set in the calling function
+   *     (we don't e-notice check it to enforce that - all payments DO have a price set - even if it is the
+   *     default one & this function asks that be set if it is the case).
+   *
+   * @return string
+   *   Text for civicrm_contribution.amount_level field.
+   */
+  public static function getAmountLevelText($params) {
+    $priceSetID = $params['priceSetId'];
+    $priceFieldSelection = self::filterPriceFieldsFromParams($priceSetID, $params);
+    $priceFieldMetadata = self::getCachedPriceSetDetail($priceSetID);
+    $displayParticipantCount = null;
+    $amount_level = array();
+    foreach ($priceFieldMetadata['fields'] as $field) {
+      if (!empty($priceFieldSelection[$field['id']])) {
+        if ($field['is_enter_qty']) {
+          $qtyString = ' - ' . (float) $params['price_' . $field['id']];
+        }
+        // We deliberately & specifically exclude contribution amount as it has a specific meaning.
+        // ie. it represents the default price field for a contribution. Another approach would be not
+        // to give it a label if we don't want it to show.
+        if ($field['label'] != ts('Contribution Amount')) {
+          $amount_level[] = $field['label'] . $qtyString;
+        }
+      }
+    }
+    return CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $amount_level) . $displayParticipantCount . CRM_Core_DAO::VALUE_SEPARATOR;
+  }
+
+  /**
+   * Get the fields relevant to the price field from the parameters.
+   *
+   * E.g we are looking for price_5 => 7 out of a big array of input parameters.
+   *
+   * @param int $priceSetID
+   * @param array $params
+   *
+   * @return array
+   *   Price fields found in the params array
+   */
+  public static function filterPriceFieldsFromParams($priceSetID, $params) {
+    $priceSet = self::getCachedPriceSetDetail($priceSetID);
+    $return = array();
+    foreach ($priceSet['fields'] as $field) {
+      if (!empty($params['price_' . $field['id']])) {
+        $return[$field['id']] = $params['price_' . $field['id']];
+      }
+    }
+    return $return;
+  }
+
+  /**
+   * Wrapper for getSetDetail with caching.
+   *
+   * We seem to be passing this array around in a painful way - presumably to avoid the hit
+   * of loading it - so lets make it callable with caching.
+   *
+   * Why not just add caching to the other function? We could do - it just seemed a bit unclear the best caching pattern
+   * & the function was already pretty fugly. Also, I feel like we need to migrate the interaction with price-sets into
+   * a more granular interaction - ie. retrieve specific data using specific functions on this class & have the form
+   * think less about the price sets.
+   *
+   * @param int $priceSetID
+   *
+   * @return array
+   */
+  public static function getCachedPriceSetDetail($priceSetID) {
+    $cacheKey = __CLASS__ . __FUNCTION__ . '_' . $priceSetID;
+    $cache = CRM_Utils_Cache::singleton();
+    $values = (array) $cache->get($cacheKey);
+    if (empty($values)) {
+      $data = self::getSetDetail($priceSetID);
+      $values = $data[$priceSetID];
+      $cache->set($cacheKey, $values);
+    }
+    return $values;
+  }
+
   /**
    * Build the price set form.
    *
index 47f2a2815c6633de5975e73c3e2e6fc4a801cbaf..ff40e8ad8fb54c3bceeeb98c432d2814c6deb038 100644 (file)
@@ -58,7 +58,7 @@ class CRM_Utils_Cache {
   /**
    * Singleton function used to manage this object.
    *
-   * @return object
+   * @return CRM_Utils_Cache_Interface
    */
   public static function &singleton() {
     if (self::$_singleton === NULL) {
index 49f5c6fd5629313624e58c691f81b920478c4bbc..fd27ea81b44bc38f5ab5b86d78700906d2518807 100644 (file)
@@ -60,54 +60,17 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
   }
 
   /**
-   * helper function to record participant with paid contribution.
-   * @param $feeTotal
-   * @param $actualPaidAmt
+   * Helper function to record participant with paid contribution.
+   *
+   * @param int $feeTotal
+   * @param int $actualPaidAmt
    *
    * @return array
    * @throws Exception
    */
-  public function _addParticipantWithPayment($feeTotal, $actualPaidAmt) {
-    // creating price set, price field
-    $paramsSet['title'] = 'Price Set';
-    $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
-    $paramsSet['is_active'] = FALSE;
-    $paramsSet['extends'] = 1;
-
-    $priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
-    CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceset->id);
-    $priceSetId = $priceset->id;
-
-    //Checking for priceset added in the table.
-    $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
-      'id', $paramsSet['title'], 'Check DB for created priceset'
-    );
-    $paramsField = array(
-      'label' => 'Price Field',
-      'name' => CRM_Utils_String::titleToVar('Price Field'),
-      'html_type' => 'Text',
-      'price' => $feeTotal,
-      'option_label' => array('1' => 'Price Field'),
-      'option_value' => array('1' => $feeTotal),
-      'option_name' => array('1' => $feeTotal),
-      'option_weight' => array('1' => 1),
-      'option_amount' => array('1' => 1),
-      'is_display_amounts' => 1,
-      'weight' => 1,
-      'options_per_line' => 1,
-      'is_active' => array('1' => 1),
-      'price_set_id' => $priceset->id,
-      'is_enter_qty' => 1,
-      'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'),
-    );
-
-    $ids = array();
-    $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids);
-
-    //Checking for priceset added in the table.
-    $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label',
-      'id', $paramsField['label'], 'Check DB for created pricefield'
-    );
+  protected function addParticipantWithPayment($feeTotal, $actualPaidAmt) {
+    $priceSetId = $this->eventPriceSetCreate($feeTotal);
+    CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId);
 
     // create participant record
     $eventId = $this->_eventId;
@@ -174,7 +137,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase {
     $feeAmt = 100;
     $amtPaid = 60;
     $balance = $feeAmt - $amtPaid;
-    list($participant, $contribution) = $this->_addParticipantWithPayment($feeAmt, $amtPaid);
+    list($participant, $contribution) = $this->addParticipantWithPayment($feeAmt, $amtPaid);
     $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event');
 
     // amount checking
diff --git a/tests/phpunit/CRM/Price/BAO/PriceSetTest.php b/tests/phpunit/CRM/Price/BAO/PriceSetTest.php
new file mode 100644 (file)
index 0000000..b751056
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Test class for CRM_Price_BAO_PriceSet.
+ */
+class CRM_Price_BAO_PriceSetTest extends CiviUnitTestCase {
+
+  /**
+   * Sets up the fixtures.
+   */
+  protected function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Tears down the fixture.
+   */
+  protected function tearDown() {
+  }
+
+  /**
+   * Test the correct amount level is returned for an event which is not presented as a price set event.
+   *
+   * (these are denoted as 'quickConfig' in the code - but quickConfig is only supposed to refer to the
+   * configuration interface - there should be no different post process.
+   */
+  public function testGetAmountLevelTextAmount() {
+    $priceSetID = $this->eventPriceSetCreate(9);
+    $priceSet = CRM_Price_BAO_PriceSet::getCachedPriceSetDetail($priceSetID);
+    $field = reset($priceSet['fields']);
+    $params = array('priceSetId' => $priceSetID, 'price_' . $field['id'] => 1);
+    $amountLevel = CRM_Price_BAO_PriceSet::getAmountLevelText($params);
+    $this->assertEquals(CRM_Core_DAO::VALUE_SEPARATOR . 'Price Field - 1' . CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel);
+  }
+
+}
index 352d6d68fe6fa269cb4d33ceeeff304af0d8e17e..3744a28cf8b0e7b52e0ef23d0657d24b2b2bf8a5 100755 (executable)
@@ -1721,7 +1721,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       'registration_end_date' => 20081015,
       'max_participants' => 100,
       'event_full_text' => 'Sorry! We are already full',
-      'is_monetory' => 0,
+      'is_monetary' => 0,
       'is_active' => 1,
       'is_show_location' => 0,
     ), $params);
@@ -3331,4 +3331,49 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     ));
   }
 
+  /**
+   * Create a price set for an event.
+   *
+   * @param int $feeTotal
+   *
+   * @return int
+   *   Price Set ID.
+   */
+  protected function eventPriceSetCreate($feeTotal) {
+    // creating price set, price field
+    $paramsSet['title'] = 'Price Set';
+    $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
+    $paramsSet['is_active'] = FALSE;
+    $paramsSet['extends'] = 1;
+
+    $priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
+    $priceSetId = $priceset->id;
+
+    //Checking for priceset added in the table.
+    $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
+      'id', $paramsSet['title'], 'Check DB for created priceset'
+    );
+    $paramsField = array(
+      'label' => 'Price Field',
+      'name' => CRM_Utils_String::titleToVar('Price Field'),
+      'html_type' => 'Text',
+      'price' => $feeTotal,
+      'option_label' => array('1' => 'Price Field'),
+      'option_value' => array('1' => $feeTotal),
+      'option_name' => array('1' => $feeTotal),
+      'option_weight' => array('1' => 1),
+      'option_amount' => array('1' => 1),
+      'is_display_amounts' => 1,
+      'weight' => 1,
+      'options_per_line' => 1,
+      'is_active' => array('1' => 1),
+      'price_set_id' => $priceset->id,
+      'is_enter_qty' => 1,
+      'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'),
+    );
+    CRM_Price_BAO_PriceField::create($paramsField);
+
+    return $priceSetId;
+  }
+
 }