X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FForm%2FContributionBase.php;h=aa08c053ce54b439956983e40a8cddfd03e94bf6;hb=34549323dc186f2fb67e4933a26c1de946a99700;hp=47c629acd6865c77c427071664d647fa11fa4989;hpb=d90e6c3baa08a8a1bdf38e34c1ead695cc2860c1;p=civicrm-core.git diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 47c629acd6..aa08c053ce 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1,34 +1,18 @@ _values['financial_type_id'])) ) { - CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); + CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); } if (empty($this->_values['is_active'])) { throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id); @@ -359,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 = [ @@ -1410,4 +1395,57 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { return new CRM_Core_Payment_Manual(); } + /** + * Get the amount for the main contribution. + * + * The goal is to expand this function so that all the argy-bargy of figuring out the amount + * winds up here as the main spaghetti shrinks. + * + * If there is a separate membership contribution this is the 'other one'. Otherwise there + * is only one. + * + * @param $params + * + * @return float + * + * @throws \CiviCRM_API3_Exception + */ + protected function getMainContributionAmount($params) { + if (!empty($params['selectMembership'])) { + if (empty($params['amount']) && !$this->_separateMembershipPayment) { + return CRM_Member_BAO_MembershipType::getMembershipType($params['selectMembership'])['minimum_fee'] ?? 0; + } + } + return $params['amount'] ?? 0; + } + + /** + * Wrapper for processAmount that also sets autorenew. + * + * @param $fields + * This is the output of the function CRM_Price_BAO_PriceSet::getSetDetail($priceSetID, FALSE, FALSE); + * And, it would make sense to introduce caching into that function and call it from here rather than + * require the $fields array which is passed from pillar to post around the form in order to pass it in here. + * @param array $params + * Params reflecting form input e.g with fields 'price_5' => 7, 'price_8' => array(7, 8) + * @param $lineItems + * Line item array to be altered. + * @param int $priceSetID + */ + public function processAmountAndGetAutoRenew($fields, &$params, &$lineItems, $priceSetID = NULL) { + CRM_Price_BAO_PriceSet::processAmount($fields, $params, $lineItems, $priceSetID); + $autoRenew = []; + $autoRenew[0] = $autoRenew[1] = $autoRenew[2] = 0; + foreach ($lineItems as $lineItem) { + if (!empty($lineItem['auto_renew']) && + is_numeric($lineItem['auto_renew']) + ) { + $autoRenew[$lineItem['auto_renew']] += $lineItem['line_total']; + } + } + if (count($autoRenew) > 1) { + $params['autoRenew'] = $autoRenew; + } + } + }