From: Seamus Lee Date: Tue, 14 Jan 2020 20:31:33 +0000 (+1100) Subject: Merge pull request #15314 from jitendrapurohit/dev-1255 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=34549323dc186f2fb67e4933a26c1de946a99700;hp=-c;p=civicrm-core.git Merge pull request #15314 from jitendrapurohit/dev-1255 dev/core#1255 - fix display of email address on pay later contribution --- 34549323dc186f2fb67e4933a26c1de946a99700 diff --combined CRM/Contribute/Form/ContributionBase.php index 59670755be,47c629acd6..aa08c053ce --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@@ -1,18 -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); @@@ -343,8 -359,7 +343,8 @@@ // 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 = [ @@@ -561,10 -576,7 +561,7 @@@ $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']); } $this->assignPaymentFields(); - - $this->assign('email', - $this->controller->exportValue('Main', "email-{$this->_bltID}") - ); + $this->assignEmailField(); // also assign the receipt_text if (isset($this->_values['receipt_text'])) { @@@ -572,6 -584,25 +569,25 @@@ } } + /** + * Assign email variable in the template. + */ + public function assignEmailField() { + //If email exist in a profile, the default billing email field is not loaded on the page. + //Hence, assign the existing location type email by iterating through the params. + if ($this->_emailExists && empty($this->_params["email-{$this->_bltID}"])) { + foreach ($this->_params as $key => $val) { + if (substr($key, 0, 6) == 'email-') { + $this->assign('email', $this->_params[$key]); + break; + } + } + } + else { + $this->assign('email', CRM_Utils_Array::value("email-{$this->_bltID}", $this->_params)); + } + } + /** * Add the custom fields. * @@@ -1379,57 -1410,4 +1395,57 @@@ 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; + } + } + } diff --combined tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php index bb88070b2c,654ecc11d1..5c32de65f4 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php @@@ -1,11 -1,27 +1,11 @@@ getPageContribution((($withPendingContribution) ? 2 : 1), $isTestContribution); $form = $this->getThankYouForm(); $form->_lineItem = []; + $form->_bltID = 5; $form->_params['contributionID'] = $pageContribution['contribution_id']; $form->_params['invoiceID'] = $pageContribution['invoice_id']; + $form->_params['email-5'] = 'demo@example.com'; $form->_params['payment_processor_id'] = $paymentProcessorID; if ($isTestContribution) { $form->_mode = 'test';