CRM-19561: When using Pay Later with a Price Set, Contribution Details in Email Recei...
authordeb.monish <monish.deb@webaccessglobal.com>
Wed, 26 Oct 2016 07:37:06 +0000 (13:07 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Wed, 26 Oct 2016 08:02:27 +0000 (13:32 +0530)
CRM/Contribute/BAO/Contribution/Utils.php
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index ab6453648d4b0ab94d5ce3249497ddb9105b8ecf..908462a87631ec21934231dde41d0859a1b6263d 100644 (file)
@@ -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
index e22f1071d59b9b308c19ba1b9a2460fd98c65143..0aa62f5b540300b66acd22b5654037480e43ad2f 100644 (file)
@@ -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.
    */