Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-792 Naprawić liczbę zamówień po usunięciu jednej z transakcji #38

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions includes/admin/payments/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ function edd_update_payment_details( $data ) {
$customer->attach_payment( $payment_id, false );

// If purchase was completed and not ever refunded, adjust stats of customers
if( 'revoked' == $status || 'publish' == $status ) {
if( 'publish' == $status ) {

$previous_customer->decrease_purchase_count();
$previous_customer->decrease_value( $new_total );
$previous_customer->decrease_value( $curr_total );

$customer->increase_purchase_count();
$customer->increase_value( $new_total );
Expand Down Expand Up @@ -250,18 +250,23 @@ function edd_update_payment_details( $data ) {
$payment->status = $status;

// Adjust total store earnings if the payment total has been changed
if ( $new_total !== $curr_total && ( 'publish' == $status || 'revoked' == $status ) ) {
if ( $new_total !== $curr_total && ( 'publish' == $status ) ) {

if ( $new_total > $curr_total ) {
// Increase if our new total is higher
$difference = $new_total - $curr_total;
edd_increase_total_earnings( $difference );
if ( !$customer_changed ) {
$customer->increase_value( $difference );
}

} elseif ( $curr_total > $new_total ) {
// Decrease if our new total is lower
$difference = $curr_total - $new_total;
edd_decrease_total_earnings( $difference );

if ( !$customer_changed ) {
$customer->decrease_value( $difference );
}
}

}
Expand Down
4 changes: 1 addition & 3 deletions includes/class-edd-customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function remove_payment( $payment_id = 0, $update_stats = true ) {

$payment = new EDD_Payment( $payment_id );

if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) {
if ( 'publish' !== $payment->status ) {
$update_stats = false;
}

Expand Down Expand Up @@ -429,7 +429,6 @@ public function increase_purchase_count( $count = 1 ) {
* @return mixed If successful, the new count, otherwise false
*/
public function decrease_purchase_count( $count = 1 ) {

// Make sure it's numeric and not negative
if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
return false;
Expand All @@ -448,7 +447,6 @@ public function decrease_purchase_count( $count = 1 ) {
}

do_action( 'edd_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id );

return $this->purchase_count;
}

Expand Down
8 changes: 0 additions & 8 deletions includes/payments/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,6 @@ function edd_delete_purchase( $payment_id = 0, $update_customer = true, $delete_
edd_decrease_total_earnings( $amount );
// Clear the This Month earnings (this_monththis_month is NOT a typo)
delete_transient( md5( 'edd_earnings_this_monththis_month' ) );

if( $customer->id && $update_customer ) {

// Decrement the stats for the customer
$customer->decrease_purchase_count();
$customer->decrease_value( $amount );

}
}

if( $customer->id && $update_customer ) {
Expand Down