4 * @method array getContribution()
5 * @method ?int getContributionID()
6 * @method $this setContributionID(?int $contributionId)
8 trait CRM_Contribute_WorkflowMessage_ContributionTrait
{
14 * @scope tokenContext as contribution
20 * @scope tokenContext as contribution_id
22 public $contributionId;
25 * Is the site configured such that tax should be displayed.
32 * @var CRM_Financial_BAO_Order
37 * Get order, if available.
39 * The order is used within the class to calculate line items etc.
41 * @return \CRM_Financial_BAO_Order|null
43 private function getOrder(): ?CRM_Financial_BAO_Order
{
44 if ($this->contributionId
) {
45 $this->order
= new CRM_Financial_BAO_Order();
46 $this->order
->setTemplateContributionID($this->contributionId
);
52 * Should line items be displayed for the contribution.
54 * This determination is based on whether the price set is quick config.
60 public $isShowLineItems;
63 * Get bool for whether a line item breakdown be displayed.
67 public function getIsShowLineItems(): bool {
68 $order = $this->getOrder();
70 // This would only be the case transitionally.
71 // Since this is a trait it is used by templates which don't (yet)
72 // always have the contribution ID available as well as migrated ones.
75 return $this->order
->getPriceSetMetadata()['is_quick_config'];
79 * Set contribution object.
81 * @param array $contribution
85 public function setContribution(array $contribution): self
{
86 $this->contribution
= $contribution;
87 if (!empty($contribution['id'])) {
88 $this->contributionId
= $contribution['id'];
94 * Extra variables to be exported to smarty based on being calculated.
96 * We export isShowTax to denote whether invoicing is enabled but
97 * hopefully at some point we will separate the assumption that invoicing
98 * and tax are a package.
100 * @param array $export
102 protected function exportExtraTplParams(array &$export): void
{
103 $export['isShowTax'] = (bool) Civi
::settings()->get('invoicing');