From a722bbf8f3733a414124592363caa79e6097836a Mon Sep 17 00:00:00 2001 From: lakshya chauhan Date: Mon, 4 Apr 2022 17:07:36 +0530 Subject: [PATCH] resolved validation issue on customer edit page --- .../admin/AdminCustomersController.php | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 3150be406..8a946965b 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -597,13 +597,22 @@ class AdminCustomersControllerCore extends AdminController 'title' => $this->l('Save'), ); - $birthday = explode('-', $this->getFieldValue($obj, 'birthday')); + if (Tools::isSubmit('submitAddcustomer')) { + $this->fields_value = array( + 'years' => Tools::getValue('years'), + 'months' => Tools::getValue('months'), + 'days' => Tools::getValue('days'), + ); + } else { + $birthday = explode('-', $this->getFieldValue($obj, 'birthday')); + + $this->fields_value = array( + 'years' => $this->getFieldValue($obj, 'birthday') ? $birthday[0] : 0, + 'months' => $this->getFieldValue($obj, 'birthday') ? $birthday[1] : 0, + 'days' => $this->getFieldValue($obj, 'birthday') ? $birthday[2] : 0, + ); + } - $this->fields_value = array( - 'years' => $this->getFieldValue($obj, 'birthday') ? $birthday[0] : 0, - 'months' => $this->getFieldValue($obj, 'birthday') ? $birthday[1] : 0, - 'days' => $this->getFieldValue($obj, 'birthday') ? $birthday[2] : 0, - ); // Added values of object Group if (!Validate::isUnsignedId($obj->id)) { @@ -878,7 +887,6 @@ class AdminCustomersControllerCore extends AdminController 'referrers' => $referrers, 'show_toolbar' => true ); - return parent::renderView(); } @@ -962,10 +970,28 @@ class AdminCustomersControllerCore extends AdminController $this->errors[] = Tools::displayError('A default customer group must be selected in group box.'); } - // Check the requires fields which are settings in the BO - $customer = new Customer(); - $this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase()); - + $days = Tools::getValue('days'); + $months = Tools::getValue('months'); + $years = Tools::getValue('years'); + + if (!$days + && !$months + && !$years + ) { + $customer = new Customer(); + $this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase()); + } else { + if (!$days) { + $this->errors[] = Tools::displayError("Please select a valid date of birthday"); + } + if (!$months) { + $this->errors[] = Tools::displayError("Please select a valid year of birthday"); + } + if (!$years) { + $this->errors[] = Tools::displayError("Please select a valid month of birthday"); + } + } + return parent::processSave(); }