예제 #1
0
 protected function customerImportOne($info, $default_language_id, $id_lang, $shop_is_feature_active, $force_ids, $validateOnly = false)
 {
     AdminImportController::setDefaultValues($info);
     if ($force_ids && isset($info['id']) && (int) $info['id']) {
         $customer = new Customer((int) $info['id']);
     } else {
         if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) {
             $customer = new Customer((int) $info['id']);
         } else {
             $customer = new Customer();
         }
     }
     $customer_exist = false;
     $autodate = true;
     if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id']) && Validate::isLoadedObject($customer)) {
         $current_id_customer = (int) $customer->id;
         $current_id_shop = (int) $customer->id_shop;
         $current_id_shop_group = (int) $customer->id_shop_group;
         $customer_exist = true;
         $customer_groups = $customer->getGroups();
         $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
     }
     // Group Importation
     if (isset($info['group']) && !empty($info['group'])) {
         foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
             $group = trim($group);
             if (empty($group)) {
                 continue;
             }
             $id_group = false;
             if (is_numeric($group) && $group) {
                 $my_group = new Group((int) $group);
                 if (Validate::isLoadedObject($my_group)) {
                     $customer_groups[] = (int) $group;
                 }
                 continue;
             }
             $my_group = Group::searchByName($group);
             if (isset($my_group['id_group']) && $my_group['id_group']) {
                 $id_group = (int) $my_group['id_group'];
             }
             if (!$id_group) {
                 $my_group = new Group();
                 $my_group->name = array($id_lang => $group);
                 if ($id_lang != $default_language_id) {
                     $my_group->name = $my_group->name + array($default_language_id => $group);
                 }
                 $my_group->price_display_method = 1;
                 if (!$validateOnly) {
                     $my_group->add();
                     if (Validate::isLoadedObject($my_group)) {
                         $id_group = (int) $my_group->id;
                     }
                 }
             }
             if ($id_group) {
                 $customer_groups[] = (int) $id_group;
             }
         }
     } elseif (empty($info['group']) && isset($customer->id) && $customer->id) {
         $customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP'));
     }
     if (isset($info['date_add']) && !empty($info['date_add'])) {
         $autodate = false;
     }
     AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer);
     if ($customer->passwd) {
         $customer->passwd = Tools::encrypt($customer->passwd);
     }
     $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop);
     $customers_shop = array();
     $customers_shop['shared'] = array();
     $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT'));
     if ($shop_is_feature_active && $id_shop_list) {
         foreach ($id_shop_list as $id_shop) {
             if (empty($id_shop)) {
                 continue;
             }
             $shop = new Shop((int) $id_shop);
             $group_shop = $shop->getGroup();
             if ($group_shop->share_customer) {
                 if (!in_array($group_shop->id, $customers_shop['shared'])) {
                     $customers_shop['shared'][(int) $id_shop] = $group_shop->id;
                 }
             } else {
                 $customers_shop[(int) $id_shop] = $group_shop->id;
             }
         }
     } else {
         $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT'));
         $default_shop->getGroup();
         $customers_shop[$default_shop->id] = $default_shop->getGroup()->id;
     }
     //set temporary for validate field
     $customer->id_shop = $default_shop->id;
     $customer->id_shop_group = $default_shop->getGroup()->id;
     if (isset($info['id_default_group']) && !empty($info['id_default_group']) && !is_numeric($info['id_default_group'])) {
         $info['id_default_group'] = trim($info['id_default_group']);
         $my_group = Group::searchByName($info['id_default_group']);
         if (isset($my_group['id_group']) && $my_group['id_group']) {
             $info['id_default_group'] = (int) $my_group['id_group'];
         }
     }
     $my_group = new Group($customer->id_default_group);
     if (!Validate::isLoadedObject($my_group)) {
         $customer->id_default_group = (int) Configuration::get('PS_CUSTOMER_GROUP');
     }
     $customer_groups[] = (int) $customer->id_default_group;
     $customer_groups = array_flip(array_flip($customer_groups));
     // Bug when updating existing user that were csv-imported before...
     if (isset($customer->date_upd) && $customer->date_upd == '0000-00-00 00:00:00') {
         $customer->date_upd = date('Y-m-d H:i:s');
     }
     $res = false;
     if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
         $res = true;
         foreach ($customers_shop as $id_shop => $id_group) {
             $customer->force_id = (bool) $force_ids;
             if ($id_shop == 'shared') {
                 foreach ($id_group as $key => $id) {
                     $customer->id_shop = (int) $key;
                     $customer->id_shop_group = (int) $id;
                     if ($customer_exist && ((int) $current_id_shop_group == (int) $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) {
                         $customer->id = (int) $current_id_customer;
                         $res &= $validateOnly || $customer->update();
                     } else {
                         $res &= $validateOnly || $customer->add($autodate);
                         if (!$validateOnly && isset($addresses)) {
                             foreach ($addresses as $address) {
                                 $address['id_customer'] = $customer->id;
                                 unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                                 Db::getInstance()->insert('address', $address, false, false);
                             }
                         }
                     }
                     if ($res && !$validateOnly && isset($customer_groups)) {
                         $customer->updateGroup($customer_groups);
                     }
                 }
             } else {
                 $customer->id_shop = $id_shop;
                 $customer->id_shop_group = $id_group;
                 if ($customer_exist && (int) $id_shop == (int) $current_id_shop) {
                     $customer->id = (int) $current_id_customer;
                     $res &= $validateOnly || $customer->update();
                 } else {
                     $res &= $validateOnly || $customer->add($autodate);
                     if (!$validateOnly && isset($addresses)) {
                         foreach ($addresses as $address) {
                             $address['id_customer'] = $customer->id;
                             unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                             Db::getInstance()->insert('address', $address, false, false);
                         }
                     }
                 }
                 if ($res && !$validateOnly && isset($customer_groups)) {
                     $customer->updateGroup($customer_groups);
                 }
             }
         }
     }
     if (isset($customer_groups)) {
         unset($customer_groups);
     }
     if (isset($current_id_customer)) {
         unset($current_id_customer);
     }
     if (isset($current_id_shop)) {
         unset($current_id_shop);
     }
     if (isset($current_id_shop_group)) {
         unset($current_id_shop_group);
     }
     if (isset($addresses)) {
         unset($addresses);
     }
     if (!$res) {
         $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be ' . ($validateOnly ? 'validated' : 'saved')), $info['email'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
         $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
     }
 }
예제 #2
0
 public function processDuplicate()
 {
     if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
         $id_product_old = $product->id;
         if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) {
             $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
             foreach ($shops as $shop) {
                 if ($product->isAssociatedToShop($shop['id_shop'])) {
                     $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
                     $product->price = $product_price->price;
                 }
             }
         }
         unset($product->id);
         unset($product->id_product);
         $product->indexed = 0;
         $product->active = 0;
         if ($product->add() && Category::duplicateProductCategories($id_product_old, $product->id) && ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false && GroupReduction::duplicateReduction($id_product_old, $product->id) && Product::duplicateAccessories($id_product_old, $product->id) && Product::duplicateFeatures($id_product_old, $product->id) && Product::duplicateSpecificPrices($id_product_old, $product->id) && Pack::duplicate($id_product_old, $product->id) && Product::duplicateCustomizationFields($id_product_old, $product->id) && Product::duplicateTags($id_product_old, $product->id) && Product::duplicateDownload($id_product_old, $product->id)) {
             if ($product->hasAttributes()) {
                 Product::updateDefaultAttribute($product->id);
             }
             if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {
                 $this->errors[] = Tools::displayError('An error occurred while copying images.');
             } else {
                 Hook::exec('actionProductAdd', array('product' => $product));
                 if (in_array($product->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION')) {
                     Search::indexation(false, $product->id);
                 }
                 $this->redirect_after = self::$currentIndex . (Tools::getIsset('id_category') ? '&id_category=' . (int) Tools::getValue('id_category') : '') . '&conf=19&token=' . $this->token;
             }
         } else {
             $this->errors[] = Tools::displayError('An error occurred while creating an object.');
         }
     }
 }
예제 #3
0
         Shop::setContext(Shop::CONTEXT_SHOP, $id);
         echo "-Context is set to " . $type . $id . " ";
         break;
     default:
         Shop::setContext(Shop::CONTEXT_ALL, null);
         echo "-Context is set to " . $type . " ";
 }
 //code v2.4.1
 $id_product = (int) Tools::getValue('id_product');
 $id_lang = (int) Context::getContext()->language->id;
 //$product = new Product($id_product, false, $id_lang,$id_shop_source,$context); //version 5.2 - Ne duplique que dans une seule langue
 $product = new Product($id_product, false, null, $id_shop_source, $context);
 //version 5.3  All languages
 //Class product:  function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
 if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) {
     $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
     foreach ($shops as $shop) {
         if ($product->isAssociatedToShop($shop['id_shop'])) {
             $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
             $product->price = $product_price->price;
         }
     }
 }
 if (Validate::isLoadedObject($product)) {
     $id_product_old = $product->id;
     for ($i = 1; $i <= $quantity; $i++) {
         echo $i;
         unset($product->id);
         unset($product->id_product);
         $product->indexed = 0;
         $product->active = 0;
 public function customerImport()
 {
     $customer_exist = false;
     $this->receiveTab();
     $handle = $this->openCsvFile();
     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
     $id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
     if (!Validate::isUnsignedId($id_lang)) {
         $id_lang = $default_language_id;
     }
     AdminImportController::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8EncodeArray($line);
         }
         $info = AdminImportController::getMaskedRow($line);
         AdminImportController::setDefaultValues($info);
         if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
             $customer = new Customer((int) $info['id']);
         } else {
             if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) {
                 $customer = new Customer((int) $info['id']);
             } else {
                 $customer = new Customer();
             }
         }
         if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) {
             $current_id_customer = $customer->id;
             $current_id_shop = $customer->id_shop;
             $current_id_shop_group = $customer->id_shop_group;
             $customer_exist = true;
             $customer_groups = $customer->getGroups();
             $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
         }
         // Group Importation
         if (isset($info['group']) && !empty($info['group'])) {
             foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
                 $group = trim($group);
                 if (empty($group)) {
                     continue;
                 }
                 $id_group = false;
                 if (is_numeric($group) && $group) {
                     $my_group = new Group((int) $group);
                     if (Validate::isLoadedObject($my_group)) {
                         $customer_groups[] = (int) $group;
                     }
                     continue;
                 }
                 $my_group = Group::searchByName($group);
                 if (isset($my_group['id_group']) && $my_group['id_group']) {
                     $id_group = (int) $my_group['id_group'];
                 }
                 if (!$id_group) {
                     $my_group = new Group();
                     $my_group->name = array($id_lang => $group);
                     if ($id_lang != $default_language_id) {
                         $my_group->name = $my_group->name + array($default_language_id => $group);
                     }
                     $my_group->price_display_method = 1;
                     $my_group->add();
                     if (Validate::isLoadedObject($my_group)) {
                         $id_group = (int) $my_group->id;
                     }
                 }
                 if ($id_group) {
                     $customer_groups[] = (int) $id_group;
                 }
             }
         } elseif (empty($info['group']) && isset($customer->id) && $customer->id) {
             $customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP'));
         }
         AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer);
         if ($customer->passwd) {
             $customer->passwd = Tools::encrypt($customer->passwd);
         }
         $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop);
         $customers_shop = array();
         $customers_shop['shared'] = array();
         $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT'));
         if (Shop::isFeatureActive() && $id_shop_list) {
             foreach ($id_shop_list as $id_shop) {
                 if (empty($id_shop)) {
                     continue;
                 }
                 $shop = new Shop((int) $id_shop);
                 $group_shop = $shop->getGroup();
                 if ($group_shop->share_customer) {
                     if (!in_array($group_shop->id, $customers_shop['shared'])) {
                         $customers_shop['shared'][(int) $id_shop] = $group_shop->id;
                     }
                 } else {
                     $customers_shop[(int) $id_shop] = $group_shop->id;
                 }
             }
         } else {
             $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT'));
             $default_shop->getGroup();
             $customers_shop[$default_shop->id] = $default_shop->getGroup()->id;
         }
         //set temporally for validate field
         $customer->id_shop = $default_shop->id;
         $customer->id_shop_group = $default_shop->getGroup()->id;
         if (isset($info['id_default_group']) && !empty($info['id_default_group']) && !is_numeric($info['id_default_group'])) {
             $info['id_default_group'] = trim($info['id_default_group']);
             $my_group = Group::searchByName($info['id_default_group']);
             if (isset($my_group['id_group']) && $my_group['id_group']) {
                 $info['id_default_group'] = (int) $my_group['id_group'];
             }
         }
         $my_group = new Group($customer->id_default_group);
         if (!Validate::isLoadedObject($my_group)) {
             $customer->id_default_group = (int) Configuration::get('PS_CUSTOMER_GROUP');
         }
         $customer_groups[] = (int) $customer->id_default_group;
         $customer_groups = array_flip(array_flip($customer_groups));
         $res = true;
         if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
             foreach ($customers_shop as $id_shop => $id_group) {
                 $customer->force_id = (bool) Tools::getValue('forceIDs');
                 if ($id_shop == 'shared') {
                     foreach ($id_group as $key => $id) {
                         $customer->id_shop = (int) $key;
                         $customer->id_shop_group = (int) $id;
                         if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) {
                             $customer->id = $current_id_customer;
                             $res &= $customer->update();
                         } else {
                             $res &= $customer->add();
                             if (isset($addresses)) {
                                 foreach ($addresses as $address) {
                                     $address['id_customer'] = $customer->id;
                                     unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                                     Db::getInstance()->insert('address', $address);
                                 }
                             }
                         }
                         if ($res && isset($customer_groups)) {
                             $customer->updateGroup($customer_groups);
                         }
                     }
                 } else {
                     $customer->id_shop = $id_shop;
                     $customer->id_shop_group = $id_group;
                     if ($customer_exist && $id_shop == $current_id_shop) {
                         $customer->id = $current_id_customer;
                         $res &= $customer->update();
                     } else {
                         $res &= $customer->add();
                         if (isset($addresses)) {
                             foreach ($addresses as $address) {
                                 $address['id_customer'] = $customer->id;
                                 unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                                 Db::getInstance()->insert('address', $address);
                             }
                         }
                     }
                     if ($res && isset($customer_groups)) {
                         $customer->updateGroup($customer_groups);
                     }
                 }
             }
         }
         unset($customer_groups);
         $customer_exist = false;
         if (!$res) {
             $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['email'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
             $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
         }
     }
     $this->closeCsvFile($handle);
 }
예제 #5
0
 public function postProcess()
 {
     $id_shops = array();
     if (Tools::isSubmit('mass_csv_form_submit')) {
         if (Shop::getContext() == Shop::CONTEXT_ALL) {
             $shops = Shop::getShops();
             if (!empty($shops)) {
                 foreach ($shops as $s) {
                     $id_shops[] = $s['id_shop'];
                 }
             }
         } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
             $shopid = Shop::getContextShopGroupID(true);
             $shops = ShopGroup::getShopsFromGroup($shopid);
             if (!empty($shops)) {
                 foreach ($shops as $s) {
                     $id_shops[] = $s['id_shop'];
                 }
             }
         }
         if (empty($id_shops)) {
             $id_shops[] = Shop::getContextShopID();
         }
         $id_shops = array_unique($id_shops);
         if (is_uploaded_file($_FILES['csv_file']['tmp_name'])) {
             $mimes = array('application/vnd.ms-excel', 'text/plain', 'text/csv', 'text/tsv');
             if (!in_array($_FILES['csv_file']['type'], $mimes)) {
                 $this->errors[] = Tools::displayError($this->l('Error : Problem with file upload. Please retry or check your file.'));
                 return false;
             }
             if (move_uploaded_file($_FILES['csv_file']['tmp_name'], $this->mod->cache_dir . $_FILES['csv_file']['name'])) {
                 $old_file_name = $_FILES['csv_file']['name'];
                 $csv_content = Tools::file_get_contents($this->mod->cache_dir . $old_file_name);
                 $array = $this->csvToArray($csv_content);
                 if (empty($array)) {
                     $this->errors[] = Tools::displayError($this->l('Error : Problem with file upload. Please retry or check your file.'));
                     parent::postProcess();
                     return false;
                 }
                 foreach ($array as $value) {
                     if (!empty($value[0])) {
                         $new = !empty($value[1]) ? trim($value[1]) : '/';
                         $type = !empty($value[2]) ? trim($value[2]) : '301';
                         $regex = !empty($value[3]) ? (int) $value[3] : 0;
                         $redirect = new Redirect();
                         $redirect->old = trim($value[0]);
                         $redirect->new = $new;
                         $redirect->type = $type;
                         $redirect->regex = (bool) $regex;
                         $redirect->active = true;
                         $redirect->add();
                         /*foreach ($id_shops as $v) {
                               $db->execute('INSERT INTO `'._DB_PREFIX_.'redirect_shop` (`id_redirect_shop`,`id_redirect`, `id_shop`) VALUES (NULL,'.(int)$redirect->id.','.(int)$v.')');
                           }*/
                     }
                 }
             }
             Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminRedirect') . '&conf=4');
         }
     }
     parent::postProcess();
 }
예제 #6
0
 public function getShopsIds()
 {
     $id_shops = array();
     if (Shop::getContext() == Shop::CONTEXT_ALL) {
         $shops = Shop::getShops();
         if (!empty($shops)) {
             foreach ($shops as $s) {
                 $id_shops[] = $s['id_shop'];
             }
         }
     } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
         $shopid = Shop::getContextShopGroupID(true);
         $shops = ShopGroup::getShopsFromGroup($shopid);
         if (!empty($shops)) {
             foreach ($shops as $s) {
                 $id_shops[] = $s['id_shop'];
             }
         }
     }
     if (empty($id_shops)) {
         $id_shops[] = Shop::getContextShopID();
     }
     $id_shops = array_unique($id_shops);
     return $id_shops;
 }
예제 #7
0
 public function customerImport()
 {
     $customer_exist = false;
     $this->receiveTab();
     $handle = $this->openCsvFile();
     AdminImportController::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8EncodeArray($line);
         }
         $info = AdminImportController::getMaskedRow($line);
         AdminImportController::setDefaultValues($info);
         if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) {
             $customer = new Customer((int) $info['id']);
             $current_id_customer = $customer->id;
             $current_id_shop = $customer->id_shop;
             $current_id_shop_group = $customer->id_shop_group;
             $customer_exist = true;
             $customer_groups = $customer->getGroups();
             $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
             foreach ($customer_groups as $key => $group) {
                 if ($group == $customer->id_default_group) {
                     unset($customer_groups[$key]);
                 }
             }
         } else {
             $customer = new Customer();
         }
         AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer);
         if ($customer->passwd) {
             $customer->passwd = Tools::encrypt($customer->passwd);
         }
         $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop);
         $customers_shop = array();
         $customers_shop['shared'] = array();
         $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT'));
         if (Shop::isFeatureActive() && $id_shop_list) {
             foreach ($id_shop_list as $id_shop) {
                 $shop = new Shop((int) $id_shop);
                 $group_shop = $shop->getGroup();
                 if ($group_shop->share_customer) {
                     if (!in_array($group_shop->id, $customers_shop['shared'])) {
                         $customers_shop['shared'][(int) $id_shop] = $group_shop->id;
                     }
                 } else {
                     $customers_shop[(int) $id_shop] = $group_shop->id;
                 }
             }
         } else {
             $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT'));
             $default_shop->getGroup();
             $customers_shop[$default_shop->id] = $default_shop->getGroup()->id;
         }
         //set temporally for validate field
         $customer->id_shop = $default_shop->id;
         $customer->id_shop_group = $default_shop->getGroup()->id;
         $res = true;
         if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
             foreach ($customers_shop as $id_shop => $id_group) {
                 if ($id_shop == 'shared') {
                     foreach ($id_group as $key => $id) {
                         $customer->id_shop = (int) $key;
                         $customer->id_shop_group = (int) $id;
                         if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) {
                             $customer->id = $current_id_customer;
                             $res &= $customer->update();
                         } else {
                             unset($customer->id);
                             $res &= $customer->add();
                             if (isset($customer_groups)) {
                                 $customer->addGroups($customer_groups);
                             }
                             if (isset($addresses)) {
                                 foreach ($addresses as $address) {
                                     $address['id_customer'] = $customer->id;
                                     unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                                     Db::getInstance()->insert('address', $address);
                                 }
                             }
                         }
                     }
                 } else {
                     $customer->id_shop = $id_shop;
                     $customer->id_shop_group = $id_group;
                     if ($customer_exist && $id_shop == $current_id_shop) {
                         $customer->id = $current_id_customer;
                         $res &= $customer->update();
                     } else {
                         unset($customer->id);
                         $res &= $customer->add();
                         if (isset($customer_groups)) {
                             $customer->addGroups($customer_groups);
                         }
                         if (isset($addresses)) {
                             foreach ($addresses as $address) {
                                 $address['id_customer'] = $customer->id;
                                 unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']);
                                 Db::getInstance()->insert('address', $address);
                             }
                         }
                     }
                 }
             }
         }
         $customer_exist = false;
         if (!$res) {
             $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['email'], isset($info['id']) ? $info['id'] : 'null');
             $this->errors[] = ($field_error !== true ? $field_error : '') . ($lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
         }
     }
     $this->closeCsvFile($handle);
 }