From 10f949e673add3da259bc686e2b35bce0caf6da1 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 15 Apr 2019 12:01:21 +1000 Subject: [PATCH] dev/core#534 Re-instate pay-now button This is regression - likely for a few months? Fix adds a unit test & does some additional tidy up We should consider for 5.12 --- CRM/Contact/Page/View/UserDashBoard.php | 3 -- CRM/Contribute/Page/UserDashboard.php | 35 ++++++++++++++++--- .../CRM/Contribute/Page/UserDashboard.tpl | 23 ++++-------- .../Contact/Page/View/UserDashBoardTest.php | 10 ++++++ 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/CRM/Contact/Page/View/UserDashBoard.php b/CRM/Contact/Page/View/UserDashBoard.php index c3eb11af2d..a1cd4da843 100644 --- a/CRM/Contact/Page/View/UserDashBoard.php +++ b/CRM/Contact/Page/View/UserDashBoard.php @@ -180,9 +180,6 @@ class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page { usort($dashboardElements, ['CRM_Utils_Sort', 'cmpFunc']); $this->assign('dashboardElements', $dashboardElements); - // return true when 'Invoices / Credit Notes' checkbox is checked - $this->assign('invoices', $dashboardOptions['Invoices / Credit Notes']); - if (!empty($dashboardOptions['Groups'])) { $this->assign('showGroup', TRUE); //build group selector diff --git a/CRM/Contribute/Page/UserDashboard.php b/CRM/Contribute/Page/UserDashboard.php index e02872e984..32c231782f 100644 --- a/CRM/Contribute/Page/UserDashboard.php +++ b/CRM/Contribute/Page/UserDashboard.php @@ -60,11 +60,23 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo // We want oldest first, just among the most recent contributions $rows = array_reverse($rows); - foreach ($rows as $index => $row) { + foreach ($rows as $index => &$row) { // This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row // which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons // and allow extensions to assign new ones through the pageRun hook - $row[0]['contribution_status_name'] = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id']);; + if ('Pending' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id'])) { + $row['buttons']['pay'] = [ + 'class' => 'button', + 'label' => ts('Pay Now'), + 'url' => CRM_Utils_System::url('civicrm/contribute/transact', [ + 'reset' => 1, + 'id' => CRM_Invoicing_Utils::getDefaultPaymentPage(), + 'ccid' => $row['contribution_id'], + 'cs' => $this->getUserChecksum(), + 'cid' => $row['contact_id'], + ]) + ]; + } } $this->assign('contribute_rows', $rows); @@ -145,13 +157,28 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo } } + /** + * Should invoice links be displayed on the template. + * + * @todo This should be moved to a hook-like structure on the invoicing class + * (currently CRM_Utils_Invoicing) with a view to possible removal from core. + */ + public function isIncludeInvoiceLinks() { + if (!CRM_Invoicing_Utils::isInvoicingEnabled()) { + return FALSE; + } + $dashboardOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'user_dashboard_options' + ); + return $dashboardOptions['Invoices / Credit Notes']; + } + /** * the main function that is called when the page * loads, it decides the which action has to be taken for the page. */ public function run() { - $this->assign('invoicing', CRM_Invoicing_Utils::isInvoicingEnabled()); - $this->assign('defaultInvoicePage', CRM_Invoicing_Utils::getDefaultPaymentPage()); + $this->assign('isIncludeInvoiceLinks', $this->isIncludeInvoiceLinks()); parent::preProcess(); $this->listContribution(); } diff --git a/templates/CRM/Contribute/Page/UserDashboard.tpl b/templates/CRM/Contribute/Page/UserDashboard.tpl index 0c25b8f393..1c3a09848f 100644 --- a/templates/CRM/Contribute/Page/UserDashboard.tpl +++ b/templates/CRM/Contribute/Page/UserDashboard.tpl @@ -35,12 +35,12 @@ {ts}Received date{/ts} {ts}Receipt Sent{/ts} {ts}Status{/ts} - {if $invoicing && $invoices} + {if $isIncludeInvoiceLinks} {/if} - {if $invoicing && $defaultInvoicePage} + {foreach from=$row.buttons item=button} - {/if} + {/foreach} {foreach from=$contribute_rows item=row} @@ -56,7 +56,7 @@ {$row.receive_date|truncate:10:''|crmDate} {$row.receipt_date|truncate:10:''|crmDate} {$row.contribution_status} - {if $invoicing && $invoices} + {if $isIncludeInvoiceLinks} {* @todo Instead of this tpl handling assign actions as an array attached the row, iterate through - will better accomodate extension overrides and competition for scarce real estate on this page*} {assign var='id' value=$row.contribution_id} @@ -75,18 +75,9 @@ {/if} {/if} - {if $defaultInvoicePage && $row.contribution_status_name == 'Pending' } - {* @todo Instead of this tpl handling assign actions as an array attached the row, iterate through - will better accomodate extension overrides and competition for scarce real estate on this page*} - - {assign var='checksum_url' value=""} - {if $userChecksum} - {assign var='checksum_url' value="&cid=$contactId&cs=$userChecksum"} - {/if} - {assign var='id' value=$row.contribution_id} - {capture assign=payNowLink}{crmURL p='civicrm/contribute/transact' q="reset=1&id=`$defaultInvoicePage`&ccid=`$id`$checksum_url"}{/capture} - {ts}Pay Now{/ts} - - {/if} + {foreach from=$row.buttons item=button} + {$button.label} + {/foreach} {/foreach} diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php index 998da15a70..db44d2e419 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php @@ -102,6 +102,14 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { 'trxn_id' => '', 'invoice_id' => '', ]); + $this->contributions[] = $this->contributionCreate([ + 'contact_id' => $this->contactID, + 'receive_date' => '2018-11-24', + 'receipt_date' => '2018-11-24', + 'trxn_id' => '', + 'invoice_id' => '', + 'contribution_status_id' => 'Pending', + ]); $recur = $this->callAPISuccess('ContributionRecur', 'create', [ 'contact_id' => $this->contactID, 'frequency_interval' => 1, @@ -117,11 +125,13 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase { 'contribution_recur_id' => $recur['id'], ]); $this->callAPISuccess('Setting', 'create', ['invoicing' => 1]); + $this->callAPISuccess('Setting', 'create', ['default_invoice_page' => $this->contributionPageCreate()['id']]); $this->runUserDashboard(); $expectedStrings = [ 'Your Contribution(s)', '', 'assertPageContains($expectedStrings); -- 2.25.1
Total AmountFinancial TypeReceived dateReceipt SentStatusCompletedPrint Invoice