From d1d16083fcc86918f28982af6a53958de10e9b95 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 17 Nov 2019 18:20:33 +1300 Subject: [PATCH] [REF] Minor simplifcation on initSet Instead of passing the information to calculate the priceSetID into this function it's more helpful to calculate it first & pass it in - this determination makes more sense on the calling form --- CRM/Contribute/Form/ContributionBase.php | 3 ++- CRM/Event/Form/Registration.php | 5 +++-- CRM/Price/BAO/PriceSet.php | 11 +---------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index e109ba927f..5dc6a299ff 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -343,7 +343,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { // get price info // CRM-5095 - CRM_Price_BAO_PriceSet::initSet($this, $this->_id, 'civicrm_contribution_page'); + $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id); + CRM_Price_BAO_PriceSet::initSet($this, 'civicrm_contribution_page', FALSE, $priceSetId); // this avoids getting E_NOTICE errors in php $setNullFields = [ diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 259b30a66b..87c8e7b7cb 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -621,10 +621,11 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { if ($discountId) { $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); - $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId); + CRM_Price_BAO_PriceSet::initSet($form, 'civicrm_event', $getAllPriceField, $priceSetId); } else { - $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField); + $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID); + CRM_Price_BAO_PriceSet::initSet($form, 'civicrm_event', $getAllPriceField, $priceSetId); } if (property_exists($form, '_context') && ($form->_context == 'standalone' diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index e2e48c9bc0..ec54607426 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -555,19 +555,13 @@ WHERE id = %1"; * This function is not really a BAO function so the location is misleading. * * @param CRM_Core_Form $form - * @param int $id * Form entity id. * @param string $entityTable * @param bool $validOnly * @param int $priceSetId * Price Set ID - * - * @return bool|false|int|null */ - public static function initSet(&$form, $id, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL) { - if (!$priceSetId) { - $priceSetId = self::getFor($entityTable, $id); - } + public static function initSet(&$form, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL) { //check if price set is is_config if (is_numeric($priceSetId)) { @@ -650,10 +644,7 @@ WHERE id = %1"; } $form->set('priceSetId', $form->_priceSetId); $form->set('priceSet', $form->_priceSet); - - return $priceSetId; } - return FALSE; } /** -- 2.25.1