From 8d273ea8cf2b1eba1873e0befcfa3f3772f1f57d Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 16 Aug 2024 12:11:09 +0200 Subject: [PATCH] automatic cancel orders instead of delete --- src/Service/OrderRepository.php | 6 ++---- src/Service/Payment.php | 17 ++++++++++------- views/admin/de/admin_lang.php | 12 ++++++------ views/admin/en/admin_lang.php | 10 +++++----- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Service/OrderRepository.php b/src/Service/OrderRepository.php index 7085acb0..757d61ab 100644 --- a/src/Service/OrderRepository.php +++ b/src/Service/OrderRepository.php @@ -134,10 +134,10 @@ public function cleanUpNotFinishedOrders() and oxtransstatus = :oxtransstatus and oxpaymenttype LIKE :oxpaymenttype and oxshopid = :oxshopid - and oxorderdate < now() - interval :sessiontime MINUTE"; + and oxorderdate + interval :sessiontime MINUTE > now()"; + /** @var \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\ResultSet $result */ $result = $this->db->select($query, [ - ':oxordernr' => '0', ':oxtransstatus' => 'NOT_FINISHED', ':oxpaymenttype' => '%oscpaypal%', ':oxshopid' => $shopId, @@ -150,8 +150,6 @@ public function cleanUpNotFinishedOrders() if ($order->load($id)) { // storno $order->cancelOrder(); - // delete - $order->delete(); } $result->fetchRow(); } diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 90451b0c..de63da9b 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -439,13 +439,16 @@ public function removeTemporaryOrder() $orderModel = oxNew(EshopModelOrder::class); $orderModel->load($sessionOrderId); - if ($orderModel->isLoaded()) { - if ($orderModel->hasOrderNumber()) { - $logger = new PayPalLogger(); - $logger->info('Cannot delete valid order with id ' . $sessionOrderId); - } else { - $orderModel->delete(); - } + if ( + $orderModel->isLoaded() && + !$orderModel->hasOrderNumber() + ) { + $orderModel->delete(); + $logger = new PayPalLogger(); + $logger->info(sprintf( + 'Temporary order without Order number and with id %s was deleted', + $sessionOrderId + )); } PayPalSession::unsetPayPalOrderId(); diff --git a/views/admin/de/admin_lang.php b/views/admin/de/admin_lang.php index 4568f58f..f432c627 100644 --- a/views/admin/de/admin_lang.php +++ b/views/admin/de/admin_lang.php @@ -256,13 +256,13 @@ Die Einstellung "3D Secure Abfrage für jede ACDC Transaktion" erzwingt die 3D Prüfung für jede ACDC Transaktion.', 'OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS_TITLE' => 'Behandlung nicht beendeter Bestellungen', - 'OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS' => 'Nicht beendete Bestellungen automatisch löschen?', + 'OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS' => 'Nicht beendete Bestellungen automatisch stornieren?', 'HELP_OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS' => 'Bei einigen PayPal-Zahlungsarten muss frühzeitig eine Bestellung angelegt werden, damit sie mit PayPal verwendet werden kann. - Es kann passieren, das Kunden während des Bezahlvorgangs den Prozess abbrechen und nicht wieder in den Shop zurück kehren. In dem Fall bleiben - nicht beendete Bestellungen übrig, die automatisch gelöscht werden können. Sie können alternaitv diese Bestellungen gern selbst kontrollieren und - händisch löschen.', - 'OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Startzeit für automatisches Löschen', - 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Wie alt müssen nicht beendete Bestellungen sein, damit sie frühestens automatisch gelöscht werden (in Minuten)?', + Es kann passieren, dass Kunden während des Bezahlvorgangs den Prozess abbrechen und nicht wieder in den Shop zurück kehren. In dem Fall bleiben + nicht beendete Bestellungen übrig, die automatisch storniert werden können. Sie können alternaitv diese Bestellungen gern selbst kontrollieren und + händisch stornieren.', + 'OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Startzeit für automatisches Stornieren', + 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Wie alt müssen nicht beendete Bestellungen sein, damit sie frühestens automatisch storniert werden (in Minuten)?', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_COUNTRY' => 'Versanddienstleister (Land)', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_PROVIDER' => 'Versanddienstleister (Anbieter)', diff --git a/views/admin/en/admin_lang.php b/views/admin/en/admin_lang.php index 6f8955ed..59e880b2 100644 --- a/views/admin/en/admin_lang.php +++ b/views/admin/en/admin_lang.php @@ -256,13 +256,13 @@ With setting "3D Secure for each ACDC transaction" 3D check will be enforced for each transaction.', 'OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS_TITLE' => 'Handling not finished orders', - 'OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS' => 'Automatically delete not finished orders?', + 'OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS' => 'Automatically cancel not finished orders?', 'HELP_OSC_PAYPAL_HANDLING_NOT_FINISHED_ORDERS' => 'For some PayPal payment methods, an order must be created in advance so that it can be used with PayPal. It can happen that customers cancel the process during the payment process and do not return to the shop. In that case stay - unfinished orders left that can be automatically deleted. Alternatively, you are welcome to check these orders yourself - delete manually.', - 'OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Start time for automatic deletion', - 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'How old do not finished orders have to be before they are automatically deleted (in minutes)?', + unfinished orders left that can be automatically canceled. Alternatively, you are welcome to check these orders yourself + cancel manually.', + 'OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Start time for automatic cancellation', + 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'How old do not finished orders have to be before they are automatically canceled (in minutes)?', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_COUNTRY' => 'Tracking Carrier (Country)', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_PROVIDER' => 'Tracking Carrier (Provider)',