[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dolibarr-dev] interface dolibarr OSC
From: |
jean |
Subject: |
[Dolibarr-dev] interface dolibarr OSC |
Date: |
Sat, 06 Oct 2007 08:40:45 +0200 |
User-agent: |
IceDove 1.5.0.12 (X11/20070607) |
Ajout de la gestion des catégories
permet de créer les équivalences catégorie OSC catégorie Dolibarr.
Un produit sera alors importé dans la bonne catégorie.
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/categories.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/categories.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/categories.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/categories.php
2007-10-03 22:45:23.000000000 +0200
@@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: categories.php,v 1.4 2007/10/01 22:08:55 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/categories.php,v $
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/categories.php,v $
*/
/**
@@ -60,14 +60,18 @@
if ($_REQUEST["action"] == 'maj')
{
+ if ($_POST["dolicat"]) $dolicatid = $_POST["dolicat"];
+ if ($_POST["catMere"]) $dolicatid = $_POST["catMere"];
+
+
$myobject=new Osc_categorie($db);
- if ($myobject->fetch_dolicat($_POST["dolicat"]) <0)
+ if ($myobject->fetch_dolicat($dolicatid) <0)
{
$mesg = "erreur dans fetch_dolicat";
}
elseif ($myobject->id > 0)
{
- $myobject->dolicatid=$_POST["dolicat"];
+ $myobject->dolicatid=$dolicatid;
$myobject->osccatid=$_POST["osccat"];
$result=$myobject->update($user);
@@ -85,7 +89,7 @@
}
else
{
- $myobject->dolicatid=$_POST["dolicat"];
+ $myobject->dolicatid=$dolicatid;
$myobject->osccatid=$_POST["osccat"];
$result=$myobject->create($user);
@@ -100,35 +104,121 @@
$mesg=$myobject->error;
}
}
+// $mesg.= " ### ".$_POST["dolicat"]." - " . $_POST["osccat"]." -
".$_POST["catMere"]. "<br/>"."variable dolicat ".$dolicatid."<br/>";
}
+else if ($_REQUEST["action"] == 'create')
+{
+ $categorie = new Categorie($db);
+ $categorie->label = $_POST["nom"];
+ $categorie->description = $_POST["description"];
+ $categorie->visible = $_POST["visible"];
+ $categorie->type = $_POST["type"];
+ if($_POST['catMere'] != "-1")
+ $categorie->id_mere = $_POST['catMere'];
+ if (! $categorie->label)
+ {
+ $categorie->error =
$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
+ $_GET["action"] = 'create';
+ }
+ else if (! $categorie->description)
+ {
+ $categorie->error =
$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description"));
+ $_GET["action"] = 'create';
+ }
+
+ if ($categorie->error =="")
+ {
+ if ($cat_id = $categorie->create() > 0)
+ {
+ $_GET["action"] = 'confirmed';
+ $_POST["addcat"] = '';
+ $myobject=new Osc_categorie($db);
+ $myobject->dolicatid=$cat_id;
+ $myobject->osccatid=$_POST["osccat"];
+
+ $result=$myobject->create($user);
+ if ($result > 0)
+ {
+ // Creation OK
+ $mesg="cration de ".$myobject->dolicatid.' -
'.$myobject->osccatid ;
+ }
+ else
+ {
+ // Creation KO
+ $mesg=$myobject->error;
+ }
+ }
+ }
+ $mesg .= ' sortie<br/>'.$categorie->error;
+}
+
+if ($_REQUEST["action"] == 'import')
+{
+ $osccat = $_GET['catid'];
+
+}
/***************************************************
* PAGE
*
-* Put here all code to build page
+* Put here all code to build page
****************************************************/
llxHeader();
-
$html=new Form($db);
+
+if ($_REQUEST["action"] == 'import')
+{
+ //titre
+ print '<table width="100%" class="noborder">';
+ print '<tr class="liste_titre">';
+ print '<td>Id</td><td>Label</td><td>Osc_id</td><td>Action</td>';
+ print '</tr>'."\n";
+ print '<tr>';
+ print '<form method="post" action="categories.php">';
+
+ print '<td><input name="osccat" value="'.$osccat.'"></td><td>';
+ print '<input type="hidden" name="action" value="maj"/>';
+// print '<input type="hidden" name="dolicat"
value="'.$obj->dolicatid.'"/>';
+ print $langs->trans("ChooseCategory").' ';
+ print $html->select_all_categories(0,$categorie->id_mere).' <input
type="submit" name="doit" class="button"
value="'.$langs->trans("Classify").'"></td>';
+ print "</form>\n";
+ print '<form method="post" action="categories.php">';
+ print '<input type="hidden" name="action" value="create"/>';
+ print '<input type="hidden" name="nom"
value="'.$_POST["description"].'"/>';
+ print '<input type="hidden" name="description"
value="'.$_POST["description"].'"/>';
+ print '<input type="hidden" name="visible" value="1"/>';
+ $parent = -1;
+ if ($_POST["catMere"] > 0) $parent = $_POST["catMere"];
+ print '<input type="hidden" name="catMere"
value="'.$parent.'"/>';
+ print '<input type="hidden" name="type" value="0"/>';
+ print '<input type="hidden" name="osccat"
value="'.$osccat.'"/>';
+ print '<td><input type="submit" name="create"
value="'.$langs->trans("create").'"></td>';
+ print '</form>';
+ print '</tr>';
+ print "</table>\n";
+}
+else
+{
-if ($mesg) print '<div class="ok">'.$mesg.'</div>';
-// Put here content of your page
-// ...
-if ($page == -1) { $page = 0 ; }
-$limit = $conf->liste_limit;
-$offset = $limit * $page ;
-
-$sql = "SELECT c.label, c.rowid dolicatid, oc.osccatid FROM
".MAIN_DB_PREFIX."categorie as c ";
-$sql .= "LEFT OUTER JOIN llx_osc_categories as oc ON oc.dolicatid = c.rowid ";
-$sql .= "WHERE c.visible = 1";
+ if ($mesg) print '<div class="ok">'.$mesg.'</div>';
-print_barre_liste("Correspondance des catégories", $page, "categories.php");
+ // Put here content of your page
+ // ...
+ if ($page == -1) { $page = 0 ; }
+ $limit = $conf->liste_limit;
+ $offset = $limit * $page ;
+
+ $sql = "SELECT c.label, c.rowid dolicatid, oc.osccatid FROM
".MAIN_DB_PREFIX."categorie as c ";
+ $sql .= "LEFT OUTER JOIN llx_osc_categories as oc ON oc.dolicatid =
c.rowid ";
+ $sql .= "WHERE c.visible = 1";
+
+ print_barre_liste("Correspondance des catégories", $page,
"categories.php");
dolibarr_syslog("Osc_Categorie.class::get_Osccat sql=".$sql);
$resql=$db->query($sql);
@@ -166,7 +256,68 @@
{
dolibarr_print_error();
}
-
+}
+ //WebService Client.
+ require_once(NUSOAP_PATH."/nusoap.php");
+ require_once("../includes/configure.php");
+
+// Set the parameters to send to the WebService
+if ($_GET["catid"]) $catid = $_GET["catid"];
+else $catid= 0;
+$parameters = array("catid"=>$catid);
+
+
+// Set the WebService URL
+$client = new soapclient_nusoap(OSCWS_DIR."ws_articles.php");
+
+$result = $client->call("get_categorylist",$parameters );
+if ($client->fault) {
+ dolibarr_print_error('',"erreur de connexion
".$client->getError());
+
+}
+elseif (!($err = $client->getError()) )
+{
+ $num=0;
+ if ($result) $num = sizeof($result);
+ $var=True;
+ $i=0;
+ print '<br/>liste categories '.$catid.'<br/>';
+ print_r($result);
+ if ($num > 0) {
+ print "<TABLE width=\"100%\" class=\"noborder\">";
+ print '<TR class="liste_titre">';
+ print "<td>id</td>";
+ print "<td>nom</td>";
+ print "<td>parent</td>";
+ print '<td>desc</td>';
+ print "<td>id dolibarr</td>";
+ print "<td>Importer</td>";
+ print "</tr>";
+
+ $dolicat = new Osc_Categorie($db);
+
+ while ($i < $num) {
+ $var=!$var;
+ print "<tr $bc[$var]>";
+ print '<td><a
href="categories.php?catid='.$result[$i]['categories_id'].'">'.$result[$i]['categories_id'].'</a></td>';
+ print "<td>".$result[$i]['categories_name']."</td>";
+ print '<td>'.$result[$i]['parent_id'].'</td>';
+ $dolicatid =
$dolicat->fetch_osccat($result[$i]['categories_id']);
+ print '<td>'.$dolicat->dolicatid.'</td>';
+ print '<td><a
href="categories.php?action=import&catid='.$result[$i]['categories_id'].'">Importer</a></td>';
+ print '<td><form method="POST" action="categorie.php">';
+ print '<input type="hidden" name="description"
value="'.$result[$i]['categories_name'].'"/>';
+ print '<input type="hidden" name="nom"
value="'.$result[$i]['categories_name'].'"/>';
+ print '<input type="hidden" name="visible" value="1"/>';
+ print '<input type="hidden" name="action"
value="import"/>';
+ print '<input type="hidden" name="catMere"
value="'.$result[$i]['parent_id'].'"/>';
+ print '<input type="hidden" name="catid"
value="'.$result[$i]['categories_id'].'"/>';
+ print '</form> </td>';
+ print "</tr>";
+ $i++;
+ }
+ }
+}
// End of page
$db->close();
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/fiche.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/fiche.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/fiche.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/fiche.php
2007-10-03 22:45:23.000000000 +0200
@@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: fiche.php,v 1.8 2007/10/01 22:08:55 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/fiche.php,v $
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/fiche.php,v $
*
*/
require("./pre.inc.php");
@@ -90,6 +90,7 @@
// exit;
}
$product = $osc_prod->osc2dolibarr($_GET['id']);
+
}
else
{
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/index.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/index.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/index.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/index.php
2007-10-03 22:45:23.000000000 +0200
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: index.php,v 1.9 2007/10/01 22:08:55 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/index.php,v $
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/index.php,v $
*/
require("./pre.inc.php");
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/osc_categories.class.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/osc_categories.class.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/osc_categories.class.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/osc_categories.class.php
2007-10-04 18:27:25.000000000 +0200
@@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: osc_categories.class.php,v 1.2 2007/10/01 22:08:55 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/osc_categories.class.php,v
$
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/osc_categories.class.php,v
$
*/
/**
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/osc_product.class.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/osc_product.class.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/osc_product.class.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/osc_product.class.php
2007-10-06 08:29:22.000000000 +0200
@@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: osc_product.class.php,v 1.14 2007/10/01 22:18:46 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/osc_product.class.php,v
$
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/osc_product.class.php,v
$
*/
/**
@@ -50,6 +50,7 @@
var $error;
+
/**
* \brief Constructeur de la classe
* \param id Id produit (0 par defaut)
@@ -103,15 +104,15 @@
return -1;
}
elseif (!($err=$client->getError()) ) {
- $this->osc_id = $obj[products_id];
- $this->osc_ref = $obj[products_model];
- $this->osc_name = $obj[products_name];
- $this->osc_desc = $obj[products_description];
- $this->osc_stock = $obj[products_quantity];
- $this->osc_four = $obj[manufacturers_id];
- $this->osc_price = $obj[products_price];
- $this->osc_image = $obj[image];
- $this->osc_catid = $obj[categories_id];
+ $this->osc_id = $obj['products_id'];
+ $this->osc_ref = $obj['products_model'];
+ $this->osc_name = $obj['products_name'];
+ $this->osc_desc = $obj['products_description'];
+ $this->osc_stock = $obj['products_quantity'];
+ $this->osc_four = $obj['manufacturers_id'];
+ $this->osc_price = $obj['products_price'];
+ $this->osc_image = $obj['image'];
+ $this->osc_catid = $obj['categories_id'];
}
else {
$this->error = 'Erreur '.$client->getError();
@@ -140,9 +141,9 @@
$product->price = convert_price($this->osc_price);
$product->tva_tx = $this->osc_tva;
$product->type = 0;
+ $product->catid = $this->get_catid($this->osc_catid) ;
$product->seuil_stock_alerte = 0; /* on force */
/* on force */
- /* à voir avec la gestion des catégories */
$product->status = 1; /* en vente */
return $product;
@@ -158,18 +159,14 @@
function transcode($oscid, $prodid)
{
-// print "entree transcode <br>";
-
/* suppression et insertion */
$sql = "DELETE FROM ".MAIN_DB_PREFIX."osc_product WHERE rowid =
".$oscid.";";
$result=$this->db->query($sql);
if ($result)
{
-// print "suppression ok ".$sql." * ".$result;
}
else
{
-// print "suppression rate ".$sql." * ".$result;
dolibarr_syslog("osc_product::transcode echec suppression");
// $this->db->rollback();
// return -1;
@@ -179,17 +176,16 @@
$result=$this->db->query($sql);
if ($result)
{
-// print "insertion ok ". $sql." ". $result;
}
else
{
-// print "insertion rate ".$sql." , ".$result;
dolibarr_syslog("osc_product::transcode echec insert");
// $this->db->rollback();
// return -1;
}
return 0;
}
+
// converti le produit osc en produit dolibarr
function get_productid($osc_product)
@@ -228,6 +224,21 @@
// test d'erreurs
if ($row) return $row[0];
else return -1;
+ }
+
+ function get_catid($osccatid)
+ {
+ require_once("./osc_categories.class.php");
+ $mycat=new Osc_categorie($this->db);
+
+ if ($mycat->fetch_osccat($osccatid) > 0)
+ {
+ $x = $mycat->dolicatid;
+ print'<p>'.$x.'</p>';
+ return $x ;
+ }
+ else return 0;
+
}
/**
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/OSCvente.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/OSCvente.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/OSCvente.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/OSCvente.php
2007-10-03 22:45:23.000000000 +0200
@@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: OSCvente.php,v 1.5 2007/10/01 22:08:55 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/OSCvente.php,v $
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/OSCvente.php,v $
*
*/
require("./pre.inc.php");
diff -Naur --exclude=CVS --exclude='.#*' --exclude='*~' --exclude=documents
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/pre.inc.php
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/pre.inc.php
---
/home/jean/projets/dolidev/sources/dolibarr_devref/dolibarr/htdocs/oscommerce_ws/produits/pre.inc.php
2007-10-03 22:44:11.000000000 +0200
+++
/home/jean/projets/dolidev/sources/dolibarr/htdocs/oscommerce_ws/produits/pre.inc.php
2007-10-03 22:45:23.000000000 +0200
@@ -18,7 +18,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: pre.inc.php,v 1.4 2007/10/01 22:08:55 eldy Exp $
- * $Source:
/sources/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/pre.inc.php,v $
+ * $Source:
/cvsroot/dolibarr/dolibarr/htdocs/oscommerce_ws/produits/pre.inc.php,v $
*/
/**