Skip to content

Commit

Permalink
Fix: progress bar stats for v2 forms using classic and multi-step tem…
Browse files Browse the repository at this point in the history
…plates
  • Loading branch information
glaubersilva committed Jul 10, 2024
1 parent 14faa94 commit f645193
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Views/Form/Templates/Classic/Classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Give\Views\Form\Templates\Classic;

use Give\DonationForms\DonationQuery;
use Give\Form\Template;
use Give\Form\Template\Hookable;
use Give\Form\Template\Scriptable;
use Give\Helpers\Form\Template as FormTemplateUtils;
use Give\Helpers\Form\Template\Utils\Frontend;
use Give\MultiFormGoals\ProgressBar\Model as ProgressBarModal;
use Give\Receipt\DonationReceipt;
use Give_Donate_Form;
use InvalidArgumentException;
Expand Down Expand Up @@ -103,7 +105,7 @@ public function loadHooks()
];

foreach ($sections as $section) {
list ($start, $end) = array_pad($section[ 'hooks' ], 2, null);
[$start, $end] = array_pad($section['hooks'], 2, null);

add_action($start, function () use ($section) {
printf('<section class="give-form-section %s">', $section[ 'class' ]);
Expand Down Expand Up @@ -289,10 +291,13 @@ public function getReceiptDetails($donationId)
return $receipt;
}

/**
* @unreleased Use sumIntendedAmount() and getDonationCount() methods to retrieve the proper values for the raised amount and donations count
*/
public function getFormGoalStats(Give_Donate_Form $form)
{
$goalStats = give_goal_progress_stats($form->get_ID());
$raisedRaw = $form->get_earnings();
$raisedRaw = (new DonationQuery())->form($form->ID)->sumIntendedAmount();

// Setup default raised value
$raised = give_currency_filter(
Expand All @@ -306,7 +311,7 @@ public function getFormGoalStats(Give_Donate_Form $form)
);

// Setup default count value
$count = $form->get_sales();
$count = (new ProgressBarModal(['ids' => [$form->get_ID()]]))->getDonationCount();

// Setup default count label
$countLabel = _n('donation', 'donations', $count, 'give');
Expand Down
11 changes: 9 additions & 2 deletions src/Views/Form/Templates/Sequoia/sections/income-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
/**
* @var int $formId
*/

use Give\DonationForms\DonationQuery;
use Give\MultiFormGoals\ProgressBar\Model as ProgressBarModal;

/**
* @unreleased Use sumIntendedAmount() and getDonationCount() methods to retrieve the proper values for the raised amount and donations count
*/
if ($form->has_goal()) : ?>
<?php
$goalStats = give_goal_progress_stats($formId);

// Setup default raised value
$raised = give_currency_filter(
give_format_amount(
$form->get_earnings(),
(new DonationQuery())->form($formId)->sumIntendedAmount(),
[
'sanitize' => false,
'decimal' => false,
Expand All @@ -19,7 +26,7 @@
);

// Setup default count value
$count = $form->get_sales();
$count = (new ProgressBarModal(['ids' => [$formId]]))->getDonationCount();;

// Setup default count label
$countLabel = _n('donation', 'donations', $count, 'give');
Expand Down

0 comments on commit f645193

Please sign in to comment.