Skip to content

Commit

Permalink
Fix breakage in message preview on workflow contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 15, 2022
1 parent 1322b78 commit 691345e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function build(array &$example): void {
private function addExampleData(GenericWorkflowMessage $messageTemplate): void {
$messageTemplate->setContact(\Civi\Test::example('entity/Contact/Barb'));
$messageTemplate->setContribution(\Civi\Test::example('entity/Contribution/Euro5990/completed'));
$mockOrder = new CRM_Financial_BAO_Order();
$mockOrder->setTemplateContributionID(50);
$mockOrder->setPriceSetToDefault('contribution');
$messageTemplate->setOrder($mockOrder);
}

}
25 changes: 22 additions & 3 deletions CRM/Contribute/WorkflowMessage/ContributionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {

/**
* @var int
* @scope tokenContext as contribution_id
* @scope tokenContext as contributionId
*/
public $contributionId;

Expand All @@ -41,7 +41,7 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
* @return \CRM_Financial_BAO_Order|null
*/
private function getOrder(): ?CRM_Financial_BAO_Order {
if ($this->contributionId) {
if (!$this->order && $this->contributionId) {
$this->order = new CRM_Financial_BAO_Order();
$this->order->setTemplateContributionID($this->contributionId);
}
Expand All @@ -65,14 +65,18 @@ private function getOrder(): ?CRM_Financial_BAO_Order {
* @return bool
*/
public function getIsShowLineItems(): bool {
if (isset($this->isShowLineItems)) {
return $this->isShowLineItems;
}

$order = $this->getOrder();
if (!$order) {
// This would only be the case transitionally.
// Since this is a trait it is used by templates which don't (yet)
// always have the contribution ID available as well as migrated ones.
return FALSE;
}
return $this->order->getPriceSetMetadata()['is_quick_config'];
return !$this->order->getPriceSetMetadata()['is_quick_config'];
}

/**
Expand All @@ -90,6 +94,21 @@ public function setContribution(array $contribution): self {
return $this;
}

/**
* Set order object.
*
* Note this is only supported for core use (specifically in example work flow)
* as the contract might change.
*
* @param CRM_Financial_BAO_Order $order
*
* @return $this
*/
public function setOrder(CRM_Financial_BAO_Order $order): self {
$this->order = $order;
return $this;
}

/**
* Extra variables to be exported to smarty based on being calculated.
*
Expand Down
7 changes: 7 additions & 0 deletions CRM/Financial/BAO/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ public function getPriceSetID(): int {
foreach ($this->getPriceOptions() as $fieldID => $valueID) {
$this->setPriceSetIDFromSelectedField($fieldID);
}
if (!$this->priceSetID && $this->getTemplateContributionID()) {
// Load the line items from the contribution.
foreach ($this->getLineItems() as $lineItem) {
return $lineItem['price_field_id.price_set_id'];
}
}
}
return $this->priceSetID;
}
Expand Down Expand Up @@ -1099,6 +1105,7 @@ protected function getLinesForContribution(): array {
'entity_id',
'entity_table',
'price_field_id',
'price_field_id.price_set_id',
'price_field_value_id',
'financial_type_id',
'label',
Expand Down

0 comments on commit 691345e

Please sign in to comment.