diff --git a/database.xml b/database.xml index 4eea210cf5f0992ad3d37115e06ed2b9a9dde0a6..915ab743e706de377091eb323f7881d70653acc8 100644 --- a/database.xml +++ b/database.xml @@ -3,6 +3,7 @@ <global> <table name="orders_process"> <field type="VARCHAR(250) NULL DEFAULT NULL">guestOrder</field> + <index>guestOrder</index> </table> </global> </database> \ No newline at end of file diff --git a/src/QUI/ERP/Order/Guest/EventHandler.php b/src/QUI/ERP/Order/Guest/EventHandler.php index f722571f3f4dadb05acd91fec15d5e9dd4cc6bdd..a472c9012121e884a2554b5a33c660846bae9f88 100644 --- a/src/QUI/ERP/Order/Guest/EventHandler.php +++ b/src/QUI/ERP/Order/Guest/EventHandler.php @@ -136,6 +136,8 @@ public static function onOrderProcessGetOrder($OrderProcess): ?AbstractOrder isset($_REQUEST['step']) && $_REQUEST['step'] === 'Processing' || $OrderProcess->getAttribute('step') === 'Processing' ) { + $email = QUI::getSession()->get(GuestOrder::EMAIL); + $result = QUI::getDataBase()->fetch([ 'from' => $Handler->table(), 'where' => [ @@ -149,7 +151,6 @@ public static function onOrderProcessGetOrder($OrderProcess): ?AbstractOrder if (isset($result[0])) { $customer = $result[0]['customer']; $customer = json_decode($customer, true); - $email = QUI::getSession()->get(GuestOrder::EMAIL); if ($customer['email'] === $email) { if (isset($customer['id'])) { @@ -158,7 +159,43 @@ public static function onOrderProcessGetOrder($OrderProcess): ?AbstractOrder try { return $Handler->get($result[0]['id']); - } catch (\Exception) { + } catch (\Exception $exception) { + } + } + } else { + // order is already in process status + // maybe payment error or async payment with error + // we have to get the current order via the url hash + // problem is, it could be an OrderInProcess or already an Order + if (isset($_REQUEST['orderHash'])) { + try { + $Order = $Handler->getOrderByHash($_REQUEST['orderHash']); + $Customer = $Order->getCustomer(); + $Address = $Customer->getStandardAddress(); + $mailList = $Address->getMailList(); + $customerMail = null; + + if (!empty($mailList)) { + $customerMail = $mailList[0]; + } + + if ($customerMail === $email) { + QUI::getSession()->set(GuestOrder::CUSTOMER_ID, $Customer->getId()); + + $table = $Handler->table(); + if ($Order instanceof QUI\ERP\Order\OrderInProcess) { + $table = $Handler->tableOrderProcess(); + } + + QUI::getDataBase()->update( + $table, + ['c_user' => QUI::getSession()->get(GuestOrder::CUSTOMER_ID)], + ['id' => $Order->getId()] + ); + + return $Order; + } + } catch (\Exception $exception) { } } } @@ -201,6 +238,17 @@ public static function onOrderProcessGetOrder($OrderProcess): ?AbstractOrder } try { + // maybe we have to set the customer uuid + // only if session exists + if (QUI::getSession()->get(GuestOrder::CUSTOMER_ID)) { + // cUser ändern + QUI::getDataBase()->update( + $Handler->tableOrderProcess(), + ['c_user' => QUI::getSession()->get(GuestOrder::CUSTOMER_ID)], + ['id' => $orderId] + ); + } + return $Handler->getOrderInProcess($orderId); } catch (\Exception $exception) { return null; @@ -343,7 +391,7 @@ public static function onQuiqqerOrderCreated(AbstractOrder $Order): void QUI::getSession()->set('guest-order-id', $Order->getId()); } - } catch (\Exception) { + } catch (\Exception $exception) { } }