Add location & relevant tests to payment.sendconfrimation
authoreileen <emcnaughton@wikimedia.org>
Fri, 15 Feb 2019 18:48:39 +0000 (07:48 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 15 Feb 2019 18:48:39 +0000 (07:48 +1300)
CRM/Financial/BAO/Payment.php
tests/phpunit/api/v3/PaymentTest.php

index c0fa6d83db2aa5a5c6f500f104775f5546c4ac69..c697606dd75f8f2816e6e390458383ca784522e9 100644 (file)
@@ -177,6 +177,13 @@ class CRM_Financial_BAO_Payment {
     ])['values'];
     if (!empty($participantRecords)) {
       $entities['event'] = civicrm_api3('Event', 'getsingle', ['id' => $participantRecords[0]['api.Participant.get']['values'][0]['event_id']]);
+      if (!empty($entities['event']['is_show_location'])) {
+        $locationParams = [
+          'entity_id' => $entities['event']['id'],
+          'entity_table' => 'civicrm_event',
+        ];
+        $entities['location'] = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
+      }
     }
 
     return $entities;
@@ -210,16 +217,14 @@ class CRM_Financial_BAO_Payment {
       'totalAmount' => $entities['payment']['total'],
       'amountOwed' => $entities['payment']['balance'],
       'paymentAmount' => $entities['payment']['total_amount'],
-      'event' => NULL,
-      'component' => 'contribution',
       'checkNumber' => CRM_Utils_Array::value('check_number', $entities['payment']),
       'receive_date' => $entities['payment']['trxn_date'],
       'paidBy' => CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $entities['payment']['payment_instrument_id']),
+      'isShowLocation' => (!empty($entities['event']) ? $entities['event']['is_show_location'] : FALSE),
+      'location' => CRM_Utils_Array::value('location', $entities),
+      'event' => CRM_Utils_Array::value('event', $entities),
+      'component' => (!empty($entities['event']) ? 'event' : 'contribution'),
     ];
-    if (!empty($entities['event'])) {
-      $templateVariables['component'] = 'event';
-      $templateVariables['event'] = $entities['event'];
-    }
 
     return self::filterUntestedTemplateVariables($templateVariables);
   }
@@ -246,6 +251,8 @@ class CRM_Financial_BAO_Payment {
       'checkNumber',
       'receive_date',
       'paidBy',
+      'isShowLocation',
+      'location',
     ];
     // Need to do these before switching the form over...
     $todoParams = [
@@ -260,8 +267,6 @@ class CRM_Financial_BAO_Payment {
       'credit_card_type',
       'credit_card_number',
       'credit_card_exp_date',
-      'isShowLocation',
-      'location',
       'eventEmail',
       '$event.participant_role',
     ];
index b4e94d656fc363fcec2bee5ac6d6ffe084266b43..59e83b08d55ec853cffc4a4a9e48c521424b50a5 100644 (file)
@@ -110,6 +110,8 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
   public function testPaymentEmailReceipt() {
     $mut = new CiviMailUtils($this);
     list($lineItems, $contribution) = $this->createParticipantWithContribution();
+    $event = $this->callAPISuccess('Event', 'get', []);
+    $this->addLocationToEvent($event['id']);
     $params = array(
       'contribution_id' => $contribution['id'],
       'total_amount' => 50,
@@ -138,6 +140,8 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
       'Paid By: Check',
       'Check Number: 345',
       'Transaction Date: August 13th, 2018  5:57 PM',
+      'event place',
+      'streety street',
     ));
     $mut->stop();
   }
@@ -630,4 +634,27 @@ class api_v3_PaymentTest extends CiviUnitTestCase {
     ));
   }
 
+  /**
+   * Add a location to our event.
+   *
+   * @param int $eventID
+   */
+  protected function addLocationToEvent($eventID) {
+    $addressParams = [
+      'name' => 'event place',
+      'street_address' => 'streety street',
+      'location_type_id' => 1,
+      'is_primary' => 1,
+    ];
+    // api requires contact_id - perhaps incorrectly but use add to get past that.
+    $address = CRM_Core_BAO_Address::add($addressParams);
+
+    $location = $this->callAPISuccess('LocBlock', 'create', ['address_id' => $address->id]);
+    $this->callAPISuccess('Event', 'create', [
+      'id' => $eventID,
+      'loc_block_id' => $location['id'],
+      'is_show_location' => TRUE,
+    ]);
+  }
+
 }