Skip to content

Commit

Permalink
Merge pull request PrestaShop#35698 from Hlavtox/order-status-failed
Browse files Browse the repository at this point in the history
Make changing order status more resilient to failed data
  • Loading branch information
nicosomb authored Mar 28, 2024
2 parents 47617b1 + 2cea4be commit e234d66
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Adapter/Order/CommandHandler/UpdateOrderStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ public function handle(UpdateOrderStatusCommand $command)
$order = $this->getOrder($command->getOrderId());
$orderState = $this->getOrderStateObject($command->getNewOrderStatusId());

/*
* Try to load current order status. There may be cases when there is none, for example when something happens
* during order creation process. That's why we check for $currentOrderState validity.
*/
$currentOrderState = $order->getCurrentOrderState();

if ($currentOrderState->id == $orderState->id) {
if (!empty($currentOrderState) && $currentOrderState->id == $orderState->id) {
throw new OrderException('The order has already been assigned this status.');
}

Expand All @@ -69,10 +72,10 @@ public function handle(UpdateOrderStatusCommand $command)

$history->changeIdOrderState((int) $orderState->id, $order, $useExistingPayments);

$carrier = new Carrier($order->id_carrier, (int) $order->getAssociatedLanguage()->getId());
$templateVars = [];

if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->getShippingNumber()) {
$carrier = new Carrier($order->id_carrier, (int) $order->getAssociatedLanguage()->getId());
$templateVars = [
'{followup}' => str_replace('@', $order->getShippingNumber(), $carrier->url),
];
Expand Down

0 comments on commit e234d66

Please sign in to comment.