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);
}
}
/**
* @var int
- * @scope tokenContext as contribution_id
+ * @scope tokenContext as contributionId
*/
public $contributionId;
* @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);
}
* @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.
// 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'];
}
/**
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.
*
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;
}
'entity_id',
'entity_table',
'price_field_id',
+ 'price_field_id.price_set_id',
'price_field_value_id',
'financial_type_id',
'label',