From e0cf48db07100a6f9e9ef950c4a2f06091c9af04 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 8 Aug 2023 15:56:50 +0530 Subject: [PATCH] Fix Phone number edit issue by guest --- controllers/front/OrderOpcController.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 17ef02dcb..c80313b1c 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -117,10 +117,29 @@ class OrderOpcControllerCore extends ParentOrderController $_POST['lastname'] = $_POST['customer_lastname']; $_POST['firstname'] = $_POST['customer_firstname']; - $this->errors = array_merge($this->errors, $this->context->customer->validateController()); $this->context->customer->newsletter = (int)Tools::isSubmit('newsletter'); $this->context->customer->optin = (int)Tools::isSubmit('optin'); $this->context->customer->is_guest = (Tools::isSubmit('is_new_customer') ? !Tools::getValue('is_new_customer', 1) : 0); + + if ($idAddressDelivery = Tools::getValue('opc_id_address_delivery')) { + $objAddress = new Address($idAddressDelivery); + if (Validate::isLoadedObject($objAddress)) { + $phoneMobile = Tools::getValue('phone_mobile'); + + if (!Validate::isPhoneNumber($phoneMobile)) { + $this->errors[] = Tools::displayError('Please enter a valid Mobile phone number.', false); + } + + if (!count($this->errors)) { + $objAddress->phone_mobile = $phoneMobile; + if (!$objAddress->save()) { + $this->errors[] = Tools::displayError('Something went wrong while saving phone number. Please try again.', false); + } + } + } + } + + $this->errors = array_merge($this->errors, $this->context->customer->validateController()); $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors,