106 lines
3.3 KiB
PHP
Executable File
106 lines
3.3 KiB
PHP
Executable File
<?php
|
|
|
|
die();
|
|
|
|
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
|
require_once(dirname(__FILE__).'/../../modules/loyalty/LoyaltyModule.php');
|
|
@ini_set('max_execution_time', 0);
|
|
|
|
if (!defined('_PS_BASE_URL_'))
|
|
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
|
|
|
$path = _PS_ROOT_DIR_.'/modules/importproduit/';
|
|
$fichier = "user2.csv";
|
|
@ini_set('display_errors', 'on');
|
|
|
|
$handle = fopen($path.$fichier, "r");
|
|
if($handle){
|
|
$row = 0;
|
|
while (($data01 = fgetcsv($handle, 100000, ";")) !== FALSE) {
|
|
|
|
$num = count($data01);
|
|
$data = utf8EncodeArray($data01);
|
|
|
|
if($row > 0){
|
|
$firstname = $data[0];
|
|
$lastname = $data[1];
|
|
$email = $data[2];
|
|
$passwd = Tools::passwdGen(8);
|
|
|
|
if($data[3] == "male"){
|
|
$civility = 1;
|
|
}
|
|
else{
|
|
$civility = 2;
|
|
}
|
|
|
|
$date = explode('/', $data[4]);
|
|
$date_anniv = $date[2] .'-'.$date[1].'-'.$date[0];
|
|
|
|
$test_email = new Customer();
|
|
$test_email->getByEmail($email);
|
|
|
|
if(empty($test_email->id)){
|
|
|
|
$customer = new Customer();
|
|
|
|
$customer->firstname = $firstname;
|
|
$customer->lastname = $lastname;
|
|
$customer->email = $email;
|
|
$customer->passwd = $passwd;
|
|
$customer->id_gender = $civility;
|
|
$customer->birthday = $date_anniv;
|
|
$customer->newsletter = 1;
|
|
|
|
|
|
$customer->add();
|
|
|
|
if(isset($customer->id)){
|
|
echo Mail::Send(
|
|
'2',
|
|
'account',
|
|
Mail::l('Welcome!'),
|
|
array(
|
|
'{firstname}' => $customer->firstname,
|
|
'{lastname}' => $customer->lastname,
|
|
'{email}' => $customer->email,
|
|
'{passwd}' => $passwd
|
|
),
|
|
$customer->email,
|
|
$customer->firstname.' '.$customer->lastname
|
|
);
|
|
|
|
echo $customer->email;
|
|
}
|
|
}
|
|
|
|
}
|
|
$row++;
|
|
|
|
echo " row :".$row."<br/>";
|
|
ob_end_flush();
|
|
flush();
|
|
ob_start();
|
|
}
|
|
fclose($handle);
|
|
echo "Import terminé";
|
|
}else{
|
|
echo "prob ouverture";
|
|
}
|
|
function utf8EncodeArray($array){
|
|
return (is_array($array) ? array_map('utf8_encode', $array) : utf8_encode($array));
|
|
}
|
|
|
|
// function registerGuest($email, $active = true){
|
|
// $id_shop = Context::getContext()->shop->id;
|
|
// $id_shop_group = Context::getContext()->shop->id_shop_group;
|
|
// $sql = 'INSERT INTO '._DB_PREFIX_.'newsletter (id_shop, id_shop_group, email, newsletter_date_add, active)
|
|
// VALUES
|
|
// ('.$id_shop.',
|
|
// '.$id_shop_group.',
|
|
// \''.pSQL($email).'\',
|
|
// NOW(),
|
|
// '.(int)$active.'
|
|
// )';
|
|
// return Db::getInstance()->execute($sql);
|
|
// }
|