With the help of this documentation :
http://wiki.dolibarr.org/index.php/Objets_m%C3%A9tiers
I try to import customer address and phone number(coordinates) from paypal paid data confirmation to dolibarr.
After that, i have to generate invoice, charge and send them to the customer email automaticly.
Right now, I am working on the customer import.
For no-regression test I use simpleTest for php.
I've made a function with customer data as parameter to import it in dolibarr.
My problem, it crash : there is 2 exeptions thrown. Not from my code but from dolibarr society class :
Exception: runTest -> testCreationTiersDansDolibarr -> Unexpected PHP error [Object of class User could not be converted to string] severity [4096] in [C:\xampp\htdocs\dolibarr\htdocs\societe\class\societe.class.php line 384]
Exception: runTest -> testCreationTiersDansDolibarr -> Unexpected PHP error [trim() expects parameter 1 to be string, array given] severity [2] in [C:\xampp\htdocs\dolibarr\htdocs\societe\class\societe.class.php line 407]
And i found no way to fix them.
If you have some clues or a full solution, it will realy help me ! I work on it from a week now without success.
[code type=php]
try {
$dsn = 'mysql:host='.HOSTNAME_SQL.';dbname='.DB_NAME;
$siteBdd = new PDO($dsn, USER_SQL, PASSWORD_SQL);
$dsn = 'mysql:host='.HOSTNAME_SQL.';dbname='.DB_DOLI_NAME;
$doliBdd = new PDO($dsn, DOLI_USER_SQL, DOLI_PASSWORD_SQL);
} catch (PDOException $e)
function addOrUpdateDolibarrClients($data)
{
global $user, $db, $lang, $langs, $conf, $doliBdd, $siteBdd ;
// 4 test la présence d'une fiche société avec l'email "username" de cmsms.
$req = $doliBdd->prepare('SELECT rowid FROM '.DOLI_PREFIX.'societe WHERE email = ? ');
$req->execute(array($data['email'])) or die(error_log('Erreur sur requête de récupération de l\'email societe dolibarr : '.$req->errorInfo()));
$isNewClient = $req->fetch();
$req->closeCursor();
// transmition des info vers dolibarr
include_once(DOLIBARR_PATH.'/htdocs/master.inc.php');
// l'auteur des modif est un robot
$user->fetch(DOLI_SCRIPT_USER_ID ,DOLI_SCRIPT_USER_NAME);
// On declare la classe que l'on va manipuler
include_once(DOLIBARR_PATH.'/htdocs/societe/class/societe.class.php');
// On cree une instance de l'objet à manipuler
$mycompany = new Societe($db);
// On renseigne ces caractéristiques
$mycompany->nom=$data['nom'];
$mycompany->email=$data['email'];
$mycompany->pays=$data['pays'];
$mycompany->ref_ext=$data['ref_ext'];
$mycompany->client=1;
$mycompany->address=$data['address'];
$mycompany->cp=$data['cp'];
$mycompany->ville=$data['ville'];
// Si on veut que l'action de création soit associé a un utilisateur 'loginuser' particulier,
// il faut decommenter cette ligne pour charger les caractéristiques de cet utilisateur.
// Si on laisse commenté, Dolibarr mettra null dans les champs du user de création ou mise à jour.
// $user->fetch('loginuser');
// ajouter ou mettre à jour les données client coté dolibarr
if ($isNewClient){
// creation nouvelle fiche
$id=$mycompany->create($user);
} else {
// mise à jour fiche existante
$mycompany->update($user);
}
}
[/code]
↧