From 3ffa3b5adcf8335825653d20ea53ddfc831516b7 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 19 May 2025 17:45:43 +0530 Subject: [PATCH] Updated the functions names --- classes/CustomerGuestDetail.php | 34 +++++++++++-------- .../admin/AdminCustomersController.php | 2 +- controllers/front/OrderOpcController.php | 6 ++-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/classes/CustomerGuestDetail.php b/classes/CustomerGuestDetail.php index e7ed8b46b..f40bf3006 100644 --- a/classes/CustomerGuestDetail.php +++ b/classes/CustomerGuestDetail.php @@ -98,7 +98,7 @@ class CustomerGuestDetailCore extends ObjectModel * * @return bool True on success, false on failure */ - public function deleteCartCustomerGuestByIdGuest() + public function deleteCustomerGuestFromCart() { return Db::getInstance()->delete( 'cart_customer_guest', @@ -108,28 +108,34 @@ class CustomerGuestDetailCore extends ObjectModel public function delete() { - $this->deleteCartCustomerGuestByIdGuest(); + $this->deleteCustomerGuestFromCart(); return parent::delete(); } /** - * Deletes the guest profiles created by customer. + * Deletes the guest profiles created by a customer. * - * @param int id_customer - * @param int offset + * @param int $idCustomer Customer ID + * @param int $offset Number of guests to skip * @return bool True on success, false on failure */ public function deleteCustomerGuestByIdCustomer($idCustomer, $offset = 0) { + $guests = $this->getCustomerGuestsByIdCustomer((int)$idCustomer); + if (empty($guests)) { + return true; + } + + $guestsToDelete = array_slice($guests, $offset); + if (empty($guestsToDelete)) { + return true; + } + $res = true; - if (($guests = $this->getCustomerGuestsByIdCustomer($idCustomer)) - && ($guests = array_slice($guests, $offset)) - ) { - foreach ($guests as $guest) { - $objCustomerGuestDetail = new CustomerGuestDetail((int) $guest['id_customer_guest_detail']); - $res &= $objCustomerGuestDetail->delete(); - } + foreach ($guestsToDelete as $guest) { + $customerGuestDetail = new CustomerGuestDetail($guest['id_customer_guest_detail']); + $res &= $customerGuestDetail->delete(); } return $res; @@ -175,7 +181,7 @@ class CustomerGuestDetailCore extends ObjectModel * @param int id_customer_guest_detail * @return array customer guest details. */ - public static function getCustomerGuestDetail($idCustomerGuestDetail) + public static function getCustomerGuestDetailById($idCustomerGuestDetail) { return Db::getInstance()->getRow(' SELECT `id_gender`, `firstname`, `lastname`, `email`, `phone` @@ -190,7 +196,7 @@ class CustomerGuestDetailCore extends ObjectModel * @param int email * @return int|false id customer guest details. */ - public static function getIdCustomerGuest($email, $idCustomer = null, $idCart = 0) + public static function getCustomerGuestByEmail($email, $idCustomer = null, $idCart = 0) { return Db::getInstance()->getValue( 'SELECT cgd.`id_customer_guest_detail` FROM `'._DB_PREFIX_.'customer_guest_detail` as cgd diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 39d33f6b7..cf9237c8b 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -1042,7 +1042,7 @@ class AdminCustomersControllerCore extends AdminController $this->errors[] = Tools::displayError('Some error ocurred while deleting the Customer'); return; } else { - if ($idCustomerGuest = CustomerGuestDetail::getIdCustomerGuest($customerEmail, false)) { + if ($idCustomerGuest = CustomerGuestDetail::getCustomerGuestByEmail($customerEmail, false)) { $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuest); $objCustomerGuestDetail->phone = preg_replace('/[0-9]/', '0', $objCustomer->phone); $objCustomerGuestDetail->email = $objCustomer->email; diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index cc4400375..a162e96d8 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -549,7 +549,7 @@ class OrderOpcControllerCore extends ParentOrderController if ($this->isLogged) { if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestIdByIdCart($this->context->cart->id)) { $this->context->smarty->assign( - 'customer_guest_detail', CustomerGuestDetail::getCustomerGuestDetail($idCustomerGuestDetail) + 'customer_guest_detail', CustomerGuestDetail::getCustomerGuestDetailById($idCustomerGuestDetail) ); } $this->context->smarty->assign('id_customer_guest_detail', $idCustomerGuestDetail); @@ -1098,9 +1098,9 @@ class OrderOpcControllerCore extends ParentOrderController $customerGuestDetailLastname = Tools::getValue('customer_guest_detail_lastname'); $customerGuestDetailEmail = Tools::getValue('customer_guest_detail_email'); $customerGuestDetailPhone = Tools::getValue('customer_guest_detail_phone'); - if ($idCustomerGuestDetail = CustomerGuestDetail::getIdCustomerGuest($customerGuestDetailEmail, $this->context->cart->id)) { + if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestByEmail($customerGuestDetailEmail, $this->context->cart->id)) { $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuestDetail); - } else if ($idCustomerGuestDetail = CustomerGuestDetail::getIdCustomerGuest($customerGuestDetailEmail, $this->context->customer->id, null)) { + } else if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestByEmail($customerGuestDetailEmail, $this->context->customer->id, null)) { $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuestDetail); } else { $objCustomerGuestDetail = new CustomerGuestDetail();