From 0fad34a03d6e3ac936b296ada8bd0db1845bce36 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 16 Feb 2019 07:48:39 +1300 Subject: [PATCH] Add location & relevant tests to payment.sendconfrimation --- CRM/Financial/BAO/Payment.php | 21 +++++++++++++-------- tests/phpunit/api/v3/PaymentTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index c0fa6d83db..c697606dd7 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -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', ]; diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index b4e94d656f..59e83b08d5 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -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, + ]); + } + } -- 2.25.1