Skip to content

Commit

Permalink
Add second currency example
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 28, 2022
1 parent 07c1cf5 commit 1c03325
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions CRM/Contribute/WorkflowMessage/Contribution/BasicContribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ public function getExamples(): iterable {
$workflows = ['contribution_online_receipt', 'contribution_offline_receipt', 'contribution_invoice_receipt'];
foreach ($workflows as $workflow) {
yield [
'name' => 'workflow/' . $workflow . '/' . $this->getExampleName(),
'title' => ts('Completed Contribution'),
'name' => 'workflow/' . $workflow . '/basic_eur',
'title' => ts('Completed Contribution, EUR'),
'tags' => ['preview'],
'workflow' => $workflow,
];
yield [
'name' => 'workflow/' . $workflow . '/' . 'basic_cad',
'title' => ts('Completed Contribution, CAD'),
'tags' => ['preview'],
'workflow' => 'contribution_offline_receipt',
'currency' => 'CAD',
];
}
}

Expand All @@ -33,27 +40,32 @@ public function getExamples(): iterable {
* @param array $example
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function build(array &$example): void {
$workFlow = WorkflowMessage::get(TRUE)->addWhere('name', '=', $example['workflow'])->execute()->first();
$this->setWorkflowName($workFlow['name']);
$messageTemplate = new $workFlow['class']();
$this->addExampleData($messageTemplate);
$this->addExampleData($messageTemplate, $example);
$example['data'] = $this->toArray($messageTemplate);
}

/**
* Add relevant example data.
*
* @param \CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt|\CRM_Contribute_WorkflowMessage_ContributionOnlineReceipt|\CRM_Contribute_WorkflowMessage_ContributionInvoiceReceipt $messageTemplate
* @param array $example
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
private function addExampleData(GenericWorkflowMessage $messageTemplate): void {
private function addExampleData(GenericWorkflowMessage $messageTemplate, $example): void {
$messageTemplate->setContact(\Civi\Test::example('entity/Contact/Barb'));
$messageTemplate->setContribution(\Civi\Test::example('entity/Contribution/Euro5990/completed'));
$contribution = \Civi\Test::example('entity/Contribution/Euro5990/completed');
if (isset($example['currency'])) {
$contribution['currency'] = $example['currency'];
}
$mockOrder = new CRM_Financial_BAO_Order();
$mockOrder->setTemplateContributionID(50);
$mockOrder->setPriceSetToDefault('contribution');
Expand Down

0 comments on commit 1c03325

Please sign in to comment.