Interfaces from foreign systems toward Dolibarr: Difference between revisions

Jump to navigation Jump to search
m
Line 28: Line 28:
== Example for a third party ==
== Example for a third party ==
Here is an example for the creation of a third party (eg customer company):
Here is an example for the creation of a third party (eg customer company):
If we make a new script or an external script, we must add at the beginning, before making anything else:
<source lang="php">
include('/pathofdolibarrhtdocs/master.inc.php');
</source>
This will initialize Dolibarr environment objects ($conf, $db, $lang and $user).
If we want that actions (create, update) are tagged with a particular user as the create/update user, we must do after the include of master.inc.php and before calling any create or update method
<source lang="php">
$user->fetch(0,'loginuser');
</source>
Now we can make our business code.


<source lang="php">
<source lang="php">
Line 33: Line 45:
include_once('/pathofdolibarrhtdocs/societe.class.php');
include_once('/pathofdolibarrhtdocs/societe.class.php');


// We create an instance of object
// We create an instance of object to manipulate
$mycompany = new Societe($db);
$mycompany = new Societe($db);


// On set properties
// We set properties on object
$mycompany->nom='Big Brother';
$mycompany->nom='Big Brother';
$mycompany->client=1;
$mycompany->client=1;
Line 53: Line 65:
// To update object
// To update object
$mycompany->update($user);
$mycompany->update($user);
</source>
Note: If we are inside an external script, you must add at the beginning of script, before the include of class we want to use:
<source lang="php">
include('/pathofdolibarrhtdocs/master.inc.php');
</source>
This will create objects $db, $lang and $user.
If we want that actions (create, update), are tagged with a particular user as the create/update user, you must do after the include of master.inc.php and before calling the create or update method
<source lang="php">
$user->fetch(0,'loginuser');
</source>
</source>


Navigation menu