From 81d4f469307fba29a8a2af8961847521b1eadf5c Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Fri, 10 Feb 2023 15:10:24 +0800 Subject: [PATCH] Fix existing customer user association #730 --- src/Controller/CustomerAppAPI/AuthController.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Controller/CustomerAppAPI/AuthController.php b/src/Controller/CustomerAppAPI/AuthController.php index 51fe4092..64dc3b4a 100644 --- a/src/Controller/CustomerAppAPI/AuthController.php +++ b/src/Controller/CustomerAppAPI/AuthController.php @@ -156,6 +156,7 @@ class AuthController extends ApiController // TODO: check if we have the number registered before and merge $dupe_sess = $this->findNumberSession($this->session->getPhoneNumber()); if ($dupe_sess != null) { + error_log("Found existing customer session for " . $this->session->getPhoneNumber()); $dupe_cust = $dupe_sess->getCustomer(); $this->session->setCustomer($dupe_cust); @@ -173,17 +174,20 @@ class AuthController extends ApiController if (!$customer_user) { $customer_user = $this->findCustomerUserByNumber($this->session->getPhoneNumber()); - if ($customer_user != null) { - // dupe_cust_user is the same as the customer we found? - $this->session->setCustomerUser($customer_user); - } else { + + if ($customer_user === null) { + error_log("Creating a new customer user for " . $this->session->getPhoneNumber()); $customer_user = new CustomerUser(); $customer_user->setCustomer($this->session->getCustomer()) ->setPhoneNumber($this->session->getPhoneNumber()); // save $this->em->persist($customer_user); + } else { + error_log("Found existing customer user for " . $this->session->getPhoneNumber()); } + + $this->session->setCustomerUser($customer_user); } $this->em->flush();