From: deb.monish Date: Wed, 26 Oct 2016 07:37:06 +0000 (+0530) Subject: CRM-19561: When using Pay Later with a Price Set, Contribution Details in Email Recei... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0335c5f1fdd7b61e95e6418081d86acfceffd007;p=civicrm-core.git CRM-19561: When using Pay Later with a Price Set, Contribution Details in Email Receipt are Blank --- diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index ab6453648d..908462a876 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -90,6 +90,11 @@ class CRM_Contribute_BAO_Contribution_Utils { CRM_Utils_Date::mysqlToIso($form->_params['receive_date']) ); + if (empty($form->_values['amount'])) { + // If the amount is not in _values[], set it + $form->_values['amount'] = $form->_params['amount']; + } + if ($isPaymentTransaction) { $contributionParams = array( 'id' => CRM_Utils_Array::value('contribution_id', $paymentParams), @@ -208,10 +213,7 @@ class CRM_Contribute_BAO_Contribution_Utils { 'payment_processor_id' => 0, ); } - elseif (empty($form->_values['amount'])) { - // If the amount is not in _values[], set it - $form->_values['amount'] = $form->_params['amount']; - } + CRM_Contribute_BAO_ContributionPage::sendMail($contactID, $form->_values, $contribution->is_test diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index e22f1071d5..0aa62f5b54 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -475,6 +475,80 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $mut->stop(); } + /** + * Ensure that price field are shown during pay later/pending Contribution + */ + public function testEmailReceiptOnPayLater() { + $donationFT = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name'); + $paramsSet = array( + 'title' => 'Price Set' . substr(sha1(rand()), 0, 4), + 'is_active' => TRUE, + 'financial_type_id' => $donationFT, + 'extends' => 2, + ); + $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); + + $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' => 'CheckBox', + 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), + 'option_value' => array('1' => 100, '2' => 200), + 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), + 'option_weight' => array('1' => 1, '2' => 2), + 'option_amount' => array('1' => 100, '2' => 200), + 'is_display_amounts' => 1, + 'weight' => 1, + 'options_per_line' => 1, + 'is_active' => array('1' => 1, '2' => 1), + 'price_set_id' => $priceset->id, + 'is_enter_qty' => 1, + 'financial_type_id' => $donationFT, + ); + $priceField = CRM_Price_BAO_PriceField::create($paramsField); + $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); + + $params = array( + 'total_amount' => 100, + 'financial_type_id' => $donationFT, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'is_email_receipt' => TRUE, + 'from_email_address' => 'test@test.com', + 'price_set_id' => $priceSetId, + 'contribution_status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name'), + ); + + foreach ($priceFieldValue['values'] as $id => $price) { + if ($price['amount'] == 100) { + $params['price_' . $priceField->id] = array($id => 1); + } + } + $form = new CRM_Contribute_Form_Contribution(); + $mut = new CiviMailUtils($this, TRUE); + $form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); + $form->testSubmit($params, CRM_Core_Action::ADD); + + $mut->checkMailLog(array( + 'Financial Type: Donation +--------------------------------------------------------- +Item Qty Each Total +---------------------------------------------------------- +Price Field - Price Field 1 1 $ 100.00 $ 100.00 +', + ) + ); + $mut->stop(); + } + /** * Test that a contribution is assigned against a pledge. */