diff --git a/src/Components/OrderExpiration/ExpireAction.php b/src/Components/OrderExpiration/ExpireAction.php index edd47656d..d14c2c756 100644 --- a/src/Components/OrderExpiration/ExpireAction.php +++ b/src/Components/OrderExpiration/ExpireAction.php @@ -14,6 +14,7 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; +use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\OrFilter; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter; use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting; use Shopware\Core\System\SalesChannel\SalesChannelEntity; @@ -78,7 +79,12 @@ private function expireOrdersInSalesChannel(SalesChannelEntity $salesChannelEnti $criteria = new Criteria(); $criteria->addAssociation('transactions.stateMachineState'); - $criteria->addFilter(new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_IN_PROGRESS)); + $criteria->addAssociation('transactions.paymentMethod'); + $criteria->addFilter(new OrFilter([ + new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_IN_PROGRESS), + new EqualsFilter('transactions.stateMachineState.technicalName', OrderTransactionStates::STATE_UNCONFIRMED) + ])); + $criteria->addFilter(new EqualsFilter('salesChannelId', $salesChannelEntity->getId())); $criteria->addFilter(new RangeFilter('orderDateTime', [RangeFilter::GTE => $date->format(Defaults::STORAGE_DATE_TIME_FORMAT)])); $criteria->addSorting(new FieldSorting('orderDateTime', FieldSorting::DESCENDING)); diff --git a/src/Service/Order/OrderExpireService.php b/src/Service/Order/OrderExpireService.php index 22a742872..0512bcd79 100644 --- a/src/Service/Order/OrderExpireService.php +++ b/src/Service/Order/OrderExpireService.php @@ -9,9 +9,9 @@ use Kiener\MolliePayments\Struct\Order\OrderAttributes; use Psr\Log\LoggerInterface; use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity; +use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates; use Shopware\Core\Checkout\Order\OrderCollection; use Shopware\Core\Checkout\Order\OrderEntity; -use Shopware\Core\Checkout\Order\OrderStates; use Shopware\Core\Framework\Context; class OrderExpireService @@ -91,7 +91,7 @@ public function cancelExpiredOrders(OrderCollection $orders, Context $context): $lastStatus = $stateMachineState->getTechnicalName(); // disregard any orders that are not in progress - if ($lastStatus !== OrderStates::STATE_IN_PROGRESS) { + if (!in_array($lastStatus, [OrderTransactionStates::STATE_IN_PROGRESS,OrderTransactionStates::STATE_UNCONFIRMED])) { continue; } diff --git a/src/Service/Order/OrderStatusUpdater.php b/src/Service/Order/OrderStatusUpdater.php index c1ed0d2a1..4fd1ba7cb 100644 --- a/src/Service/Order/OrderStatusUpdater.php +++ b/src/Service/Order/OrderStatusUpdater.php @@ -102,7 +102,7 @@ public function updatePaymentStatus(OrderTransactionEntity $transaction, string { # if we are already in_progress...then don't switch to OPEN again # otherwise SEPA bank transfer would switch back to OPEN - if ($currentShopwareStatusKey !== OrderTransactionStates::STATE_IN_PROGRESS || $context->hasState(self::ORDER_STATE_FORCE_OPEN)) { + if (! in_array($currentShopwareStatusKey, [OrderTransactionStates::STATE_IN_PROGRESS, OrderTransactionStates::STATE_UNCONFIRMED]) || $context->hasState(self::ORDER_STATE_FORCE_OPEN)) { $addLog = true; $this->transactionTransitionService->reOpenTransaction($transaction, $context); } diff --git a/src/Service/Transition/TransactionTransitionService.php b/src/Service/Transition/TransactionTransitionService.php index cb0bc8265..8c8b5a1bd 100644 --- a/src/Service/Transition/TransactionTransitionService.php +++ b/src/Service/Transition/TransactionTransitionService.php @@ -45,28 +45,20 @@ public function __construct( public function processTransaction(OrderTransactionEntity $transaction, Context $context): void { - // Shopware added in_progress status with version 6.2, so this ensures backward compatibility - if (!defined('Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates::STATE_IN_PROGRESS')) { - // set open status in < sw6.2 - $this->reOpenTransaction($transaction, $context); - - return; - } - $technicalName = ($transaction->getStateMachineState() instanceof StateMachineStateEntity) ? $transaction->getStateMachineState()->getTechnicalName() : ''; - if ($this->isFinalOrTargetStatus($technicalName, [OrderTransactionStates::STATE_IN_PROGRESS])) { + if ($this->isFinalOrTargetStatus($technicalName, [OrderTransactionStates::ACTION_PROCESS_UNCONFIRMED])) { return; } $entityId = $transaction->getId(); $availableTransitions = $this->getAvailableTransitions($entityId, $context); - if (!$this->transitionIsAllowed(StateMachineTransitionActions::ACTION_DO_PAY, $availableTransitions)) { + if (!$this->transitionIsAllowed(StateMachineTransitionActions::ACTION_PROCESS_UNCONFIRMED, $availableTransitions)) { $this->reOpenTransaction($transaction, $context); } - $this->performTransition($entityId, StateMachineTransitionActions::ACTION_DO_PAY, $context); + $this->performTransition($entityId, StateMachineTransitionActions::ACTION_PROCESS_UNCONFIRMED, $context); } public function reOpenTransaction(OrderTransactionEntity $transaction, Context $context): void @@ -96,28 +88,20 @@ public function reOpenTransaction(OrderTransactionEntity $transaction, Context $ public function payTransaction(OrderTransactionEntity $transaction, Context $context): void { - // backwards compatibility, the former status StateMachineTransitionActions::ACTION_PAY='pay' does not exist any more - // the constant ACTION_PAID has been added with sw 6.2 and should be used instead of legacy ACTION_PAY - $payActionName = 'pay'; - - if (defined('Shopware\Core\System\StateMachine\Aggregation\StateMachineTransition\StateMachineTransitionActions::ACTION_PAID')) { - $payActionName = StateMachineTransitionActions::ACTION_PAID; - } - $currentStatus = ($transaction->getStateMachineState() instanceof StateMachineStateEntity) ? $transaction->getStateMachineState()->getTechnicalName() : ''; - if ($this->isFinalOrTargetStatus($currentStatus, [$payActionName])) { + if ($this->isFinalOrTargetStatus($currentStatus, [StateMachineTransitionActions::ACTION_PAID])) { return; } $entityId = $transaction->getId(); $availableTransitions = $this->getAvailableTransitions($entityId, $context); - if (!$this->transitionIsAllowed($payActionName, $availableTransitions)) { + if (!$this->transitionIsAllowed(StateMachineTransitionActions::ACTION_PAID, $availableTransitions)) { $this->reOpenTransaction($transaction, $context); } - $this->performTransition($entityId, $payActionName, $context); + $this->performTransition($entityId, StateMachineTransitionActions::ACTION_PAID, $context); } public function cancelTransaction(OrderTransactionEntity $transaction, Context $context): void @@ -140,13 +124,6 @@ public function cancelTransaction(OrderTransactionEntity $transaction, Context $ public function failTransaction(OrderTransactionEntity $transaction, Context $context): void { - // Shopware added failed status with version 6.2, so this ensures backward compatibility - if (!defined('Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates::STATE_FAILED')) { - $this->cancelTransaction($transaction, $context); - - return; - } - $currentStatus = ($transaction->getStateMachineState() instanceof StateMachineStateEntity) ? $transaction->getStateMachineState()->getTechnicalName() : ''; if ($this->isFinalOrTargetStatus($currentStatus, [OrderTransactionStates::STATE_CANCELLED, OrderTransactionStates::STATE_FAILED])) { @@ -165,13 +142,6 @@ public function failTransaction(OrderTransactionEntity $transaction, Context $co public function authorizeTransaction(OrderTransactionEntity $transaction, Context $context): void { - // Shopware added authorized status with version 6.4.1, so this ensures backward compatibility - if (!defined('Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates::STATE_AUTHORIZED')) { - $this->payTransaction($transaction, $context); - - return; - } - $authorizedState = OrderTransactionStates::STATE_AUTHORIZED; $currentStatus = ($transaction->getStateMachineState() instanceof StateMachineStateEntity) ? $transaction->getStateMachineState()->getTechnicalName() : '';