From aa2f9bf88043300aad3853a79e2f23e86e766237 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 26 Sep 2024 12:02:02 +0530 Subject: [PATCH] Added: Customer phone number in the customer import process --- controllers/admin/AdminImportController.php | 22 ++++++++++++++++++--- docs/csv_import/customers_import.csv | 20 +++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index b66f7a772..f7b347fc7 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -318,8 +318,10 @@ class AdminImportControllerCore extends AdminController ); break; case $this->entities[$this->l('Customers')]: - //Overwrite required_fields AS only email is required whereas other entities $this->required_fields = array('email', 'passwd', 'lastname', 'firstname'); + if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) { + $this->required_fields[] = 'phone'; + } $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), @@ -331,6 +333,7 @@ class AdminImportControllerCore extends AdminController 'birthday' => array('label' => $this->l('Birthday (yyyy-mm-dd)')), 'lastname' => array('label' => $this->l('Last Name *')), 'firstname' => array('label' => $this->l('First Name *')), + 'phone' => array('label' => $this->l('Phone'). (Configuration::get('PS_ONE_PHONE_AT_LEAST') ? ' *' : '' )), 'newsletter' => array('label' => $this->l('Newsletter (0/1)')), 'optin' => array('label' => $this->l('Opt-in (0/1)')), 'group' => array('label' => $this->l('Groups (x,y,z...)')), @@ -2699,6 +2702,10 @@ class AdminImportControllerCore extends AdminController $convert = Tools::getValue('convert'); $force_ids = Tools::getValue('forceIDs'); + $phoneRequired = false; + if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) { + $phoneRequired = true; + } for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if ($convert) { @@ -2707,7 +2714,13 @@ class AdminImportControllerCore extends AdminController $info = AdminImportController::getMaskedRow($line); $has_required_fields = $this->checkRequiredFields($info, 'firstname'); - if ($has_required_fields) { + if ($phoneRequired && !Validate::isPhoneNumber(trim($info['phone']))) { + $this->errors[] = sprintf( + Tools::displayError('Invalid phone for %1$s (ID: %2$s).'), + $info['email'], + (isset($info['id']) && !empty($info['id']))? $info['id'] : 'null' + ); + } else if ($has_required_fields) { AdminImportController::setDefaultValues($info); $customerExists = false; if (isset($info['id']) @@ -2723,7 +2736,7 @@ class AdminImportControllerCore extends AdminController $customer->force_id = $info['id']; } } else { - $customer = new Customer(); + $customer = new Customer(); } $customer_exist = false; @@ -2833,6 +2846,9 @@ class AdminImportControllerCore extends AdminController if ($res && isset($customer_groups)) { $customer->updateGroup($customer_groups); + if ($phoneRequired) { + CartCustomerGuestDetail::updateCustomerPhoneNumber($customer->email, $customer->phone); + } } } } diff --git a/docs/csv_import/customers_import.csv b/docs/csv_import/customers_import.csv index 9f801fc00..a44de3d3d 100644 --- a/docs/csv_import/customers_import.csv +++ b/docs/csv_import/customers_import.csv @@ -1,10 +1,10 @@ -Customer ID;Active (0/1);Titles ID (Mr = 1, Mrs = 2, else 0);Email *;Password *;Birthday (yyyy-mm-dd);Last Name *;First Name *;Newsletter (0/1);Opt-in (0/1);Groups (x,y,z...);Default Group ID -1;1;1;peterpan@qloapps.com;123456789;1987-04-02;Pan;Peter;1;0;Customer;3 -2;1;2;monkeydluffy@qloapps.com;123456789;1989-11-12;Luffy;Monkey D;1;0;Customer;3 -3;1;2;tigerlily@qloapps.com;123456789;1982-02-28;Lily;Tiger;1;0;Customer;3 -4;1;1;jameshook@qloapps.com;123456789;1952-12-04;Hook;James;0;1;Guest;2 -5;1;2;tinkerbell@qloapps.com;123456789;1900-01-01;Bell;Tinker;1;1;Customer;3 -6;1;1;bobsmee@qloapps.com;123456789;1971-10-21;Smee;Bob;1;1;Customer;3 -7;1;1;tictaccrocodile@qloapps.com;123456789;1991-09-27;Crocodile;Tictac;0;0;Guest;2 -8;1;1;jackbanning@qloapps.com;123456789;2003-07-05;Banning;Jack;0;0;Visitor;1 -9;0;2;maggiedoe@qloapps.com;123456789;2006-02-27;Doe;Maggie;0;0;Visitor;1 +Customer ID;Active (0/1);Titles ID (Mr = 1, Mrs = 2, else 0);Email *;Password *;Birthday (yyyy-mm-dd);Last Name *;First Name *;Phone;Newsletter (0/1);Opt-in (0/1);Groups (x,y,z...);Default Group ID +1;1;1;peterpan@qloapps.com;123456789;1987-04-02;Pan;Peter;1234567890;1;0;Customer;3 +2;1;2;monkeydluffy@qloapps.com;123456789;1989-11-12;Luffy;Monkey D;1234567890;1;0;Customer;3 +3;1;2;tigerlily@qloapps.com;123456789;1982-02-28;Lily;Tiger;1234567890;1;0;Customer;3 +4;1;1;jameshook@qloapps.com;123456789;1952-12-04;Hook;James;1234567890;0;1;Guest;2 +5;1;2;tinkerbell@qloapps.com;123456789;1900-01-01;Bell;Tinker;1234567890;1;1;Customer;3 +6;1;1;bobsmee@qloapps.com;123456789;1971-10-21;Smee;Bob;1234567890;1;1;Customer;3 +7;1;1;tictaccrocodile@qloapps.com;123456789;1991-09-27;Crocodile;Tictac;1234567890;0;0;Guest;2 +8;1;1;jackbanning@qloapps.com;123456789;2003-07-05;Banning;Jack;1234567890;0;0;Visitor;1 +9;0;2;maggiedoe@qloapps.com;123456789;2006-02-27;Doe;Maggie;1234567890;0;0;Visitor;1