From 51140c22375857ff949ef45c2909fab286117a0f Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 2 Oct 2023 10:57:15 +1300 Subject: [PATCH] Move the participantCount logic to the template --- .../WorkflowMessage/ContributionTrait.php | 31 +++++++++++++++++ .../WorkflowMessage/ParticipantTrait.php | 34 ++++++++++++++++++- .../event_offline_receipt_html.tpl | 26 +++----------- 3 files changed, 69 insertions(+), 22 deletions(-) diff --git a/CRM/Contribute/WorkflowMessage/ContributionTrait.php b/CRM/Contribute/WorkflowMessage/ContributionTrait.php index 81e32f49b4..b7baed4edb 100644 --- a/CRM/Contribute/WorkflowMessage/ContributionTrait.php +++ b/CRM/Contribute/WorkflowMessage/ContributionTrait.php @@ -30,6 +30,18 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { */ public $isShowTax; + /** + * Is it a good idea to show the line item subtotal. + * + * This would be true if at least one line has a quantity > 1. + * Otherwise it is very repetitive. + * + * @var bool + * + * @scope tplParams + */ + public $isShowLineSubtotal; + /** * Line items associated with the contribution. * @@ -109,6 +121,25 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { return FALSE; } return !$this->order->getPriceSetMetadata()['is_quick_config']; + return $this->isShowLineItems; + } + + /** + * Is it a good idea to show the line item subtotal. + * + * This would be true if at least one line has a quantity > 1. + * Otherwise it is very repetitive. + * + * @return bool + * @throws \CRM_Core_Exception + */ + public function getIsShowLineSubtotal(): bool { + foreach ($this->getLineItems() as $lineItem) { + if ((int) $lineItem['qty'] > 1) { + return TRUE; + } + } + return FALSE; } /** diff --git a/CRM/Event/WorkflowMessage/ParticipantTrait.php b/CRM/Event/WorkflowMessage/ParticipantTrait.php index 92d5409c3a..a25d5ac045 100644 --- a/CRM/Event/WorkflowMessage/ParticipantTrait.php +++ b/CRM/Event/WorkflowMessage/ParticipantTrait.php @@ -37,6 +37,19 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait { */ public $isPrimary; + /** + * Should a participant count column be shown. + * + * This would be true if there is a line item on the receipt + * with more than one participant in it. Otherwise it's confusing to + * show. + * + * @var bool + * + * @scope tplParams as isShowParticipantCount + */ + public $isShowParticipantCount; + /** * @var int * @@ -152,7 +165,26 @@ trait CRM_Event_WorkflowMessage_ParticipantTrait { } /** - * Set contribution object. + * It is a good idea to show the participant count column. + * + * This would be true if there is a line item on the receipt + * with more than one participant in it. Otherwise it's confusing to + * show. + * + * @return bool + * @throws \CRM_Core_Exception + */ + public function getIsShowParticipantCount(): bool { + foreach ($this->getLineItems() as $lineItem) { + if ((int) $lineItem['participant_count'] > 1) { + return TRUE; + } + } + return FALSE; + } + + /** + * Set participant object. * * @param array $participant * diff --git a/xml/templates/message_templates/event_offline_receipt_html.tpl b/xml/templates/message_templates/event_offline_receipt_html.tpl index 2226410129..68b1b1ea32 100644 --- a/xml/templates/message_templates/event_offline_receipt_html.tpl +++ b/xml/templates/message_templates/event_offline_receipt_html.tpl @@ -164,7 +164,6 @@ {if {event.is_monetary|boolean}} - {event.fee_label} @@ -193,7 +192,7 @@ {ts}Tax Amount{/ts} {/if} {ts}Total{/ts} - {if !empty($pricesetFieldsCount)} + {if $iShowParticipantCount} {ts}Total Participants{/ts} {/if} @@ -215,7 +214,7 @@ {$line.line_total+$line.tax_amount|crmMoney:$currency} - {if !empty($pricesetFieldsCount)} + {if $isShowParticipantCount} {$line.participant_count} {/if} @@ -289,25 +288,10 @@ {contribution.total_amount} {if !empty($hookDiscount.message)}({$hookDiscount.message}){/if} - {if !empty($pricesetFieldsCount)} + {if $isShowParticipantCount} - - {ts}Total Participants{/ts} - - {assign var="count" value= 0} - {foreach from=$lineItem item=pcount} - {assign var="lineItemCount" value=0} - {if $pcount neq 'skip'} - {foreach from=$pcount item=p_count} - {assign var="lineItemCount" value=$lineItemCount+$p_count.participant_count} - {/foreach} - {if $lineItemCount < 1}{assign var="lineItemCount" value=1} - {/if} - {assign var="count" value=$count+$lineItemCount} - {/if} - {/foreach} - {$count} - + {ts}Total Participants{/ts} + {$line.participant_count} {/if} {if {contribution.is_pay_later|boolean} && {contribution.balance_amount|boolean}} -- 2.25.1