Skip to content

Commit

Permalink
Fix issues with order status update
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Aug 23, 2024
1 parent 224e8a2 commit 526c7b9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ public function handle(GetOrderForApprovalReversedQuery $query)
}

$hasBeenCanceled = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_CANCELED)));
$hasBeenPaid = $order->hasBeenPaid();
$hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED)));
$hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID)));

return new GetOrderForApprovalReversedQueryResult(
(int) $order->id,
(bool) $order->hasBeenPaid(),
$hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid,
(bool) $hasBeenCanceled
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@

namespace PrestaShop\Module\PrestashopCheckout\Order\QueryHandler;

use Configuration;
use Order;
use OrderPayment;
use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;
use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentCompletedQuery;
use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentCompletedQueryResult;
use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use PrestaShopCollection;
use PrestaShopDatabaseException;
Expand Down Expand Up @@ -89,10 +91,14 @@ public function handle(GetOrderForPaymentCompletedQuery $query)
}
}

$hasBeenPaid = $order->hasBeenPaid();
$hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED)));
$hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID)));

return new GetOrderForPaymentCompletedQueryResult(
(int) $order->id,
(int) $order->id_cart,
(bool) $order->hasBeenPaid(),
$hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid,
(string) $order->total_paid,
(int) $order->id_currency,
$psCheckoutCart->getPaypalFundingSource(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

namespace PrestaShop\Module\PrestashopCheckout\Order\QueryHandler;

use Configuration;
use Order;
use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;
use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentRefundedQuery;
use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentRefundedQueryResult;
use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use PrestaShopCollection;
use PrestaShopDatabaseException;
Expand Down Expand Up @@ -78,12 +80,16 @@ public function handle(GetOrderForPaymentRefundedQuery $query)
throw new OrderNotFoundException('No PrestaShop Order associated to this PayPal Order at this time.');
}

$hasBeenPaid = $order->hasBeenPaid();
$hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED)));
$hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID)));

return new GetOrderForPaymentRefundedQueryResult(
(int) $order->id,
(int) $order->getCurrentState(),
(bool) $order->hasBeenPaid(),
(bool) count($order->getHistory((int) $order->id_lang, (int) \Configuration::get('PS_CHECKOUT_STATE_PARTIALLY_REFUNDED'))),
(bool) count($order->getHistory((int) $order->id_lang, (int) \Configuration::get('PS_CHECKOUT_STATE_REFUNDED'))),
$hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid,
(bool) count($order->getHistory((int) $order->id_lang, (int) Configuration::get('PS_CHECKOUT_STATE_PARTIALLY_REFUNDED'))),
(bool) count($order->getHistory((int) $order->id_lang, (int) Configuration::get('PS_CHECKOUT_STATE_REFUNDED'))),
(string) $order->getTotalPaid(),
(int) $order->id_currency
);
Expand Down
27 changes: 9 additions & 18 deletions src/Order/QueryHandler/GetOrderForPaymentReversedQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@

namespace PrestaShop\Module\PrestashopCheckout\Order\QueryHandler;

use Configuration;
use Order;
use OrderSlip;
use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;
use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentReversedQuery;
use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentReversedQueryResult;
use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use PrestaShopCollection;
use PrestaShopDatabaseException;
Expand Down Expand Up @@ -79,25 +80,15 @@ public function handle(GetOrderForPaymentReversedQuery $query)
throw new OrderNotFoundException('No PrestaShop Order associated to this PayPal Order at this time.');
}

$hasBeenPaid = $order->hasBeenPaid();
$hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED)));
$hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID)));
$hasBeenTotallyRefunded = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_REFUNDED)));

return new GetOrderForPaymentReversedQueryResult(
(int) $order->id,
(bool) $order->hasBeenPaid(),
$this->hasBeenTotallyRefunded($order)
$hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid,
(bool) $hasBeenTotallyRefunded
);
}

private function hasBeenTotallyRefunded(Order $order)
{
/** @var OrderSlip[] $orderSlips */
$orderSlips = $order->getOrderSlipsCollection()->getResults();
$refundAmount = 0;

if (!empty($orderSlips)) {
foreach ($orderSlips as $orderSlip) {
$refundAmount += $orderSlip->amount + $orderSlip->shipping_cost_amount;
}
}

return $refundAmount >= $order->total_paid;
}
}

0 comments on commit 526c7b9

Please sign in to comment.