2 /***************************************************************
3 *Author: Holger Lindemann
4 *Copyright: (c) 2004 Lx-System
6 *eMail: info@lx-system.de
8 *Shop: xtCommerce 2.0 RC 1.2
9 ***************************************************************/
11 require_once "shoplib.php";
12 $LAND=array("Germany"=>"D");
14 function createCategory($name,$maingroup) {
16 $newID=uniqid(rand());
17 $sql="insert into categories (categories_image,parent_id,date_added) values ('$newID',$maingroup,now())";
18 $rc=query("shop",$sql,"createCategory");
19 $sql="select * from categories where categories_image = '$newID'";
20 $rs=getAll("shop",$sql,"createCategory");
21 $id=$rs[0]["categories_id"];
22 $sql="update categories set categories_image = null where categories_id=$id";
23 $rc=query("shop",$sql,"createCategory");
25 foreach ($langs as $LANG) {
26 $sql="insert into categories_description (categories_id,language_id,categories_name) values ($id,$LANG,'$name')";
27 $rc=query("shop",$sql,"createCategory");
28 if ($rc === -99) break;
30 return ($rc === -99)?false:$id;
32 function getCategory($name) {
33 if (empty($name)) $name="Default";
34 $tmp=split("!",$name);
39 $sql="select D.*,C.parent_id from categories C left join categories_description D on C.categories_id=D.categories_id ";
40 $sql.="where categories_name like '".$tmp[$i]."' and C.parent_id=$maingroup";
41 $rs=getAll("shop",$sql,"getCategory");
42 if ($rs[0]["categories_id"]) {
43 $maingroup=$rs[0]["categories_id"];
44 echo $maingroup.":".$rs[0]["categories_name"]." ";
49 } while ($rs and $found and $i<count($tmp));
50 for (;$i<count($tmp); $i++) {
51 $maingroup=createCategory($tmp[$i],$maingroup);
55 function insartikel($data) {
56 global $header,$tax,$defLang;
57 $newID=uniqid(rand());
58 $sql="insert into products (products_model,products_image) values ('".$data[array_search("products_model")]."','$newID')";
59 $rc=query("shop",$sql,"insartikel");
60 $sql="select * from products where products_image='$newID'";
61 $rs=getAll("shop",$sql,"insartikel");
62 $sql="update products set products_image=null,products_status=1 where products_id=".$rs[0]["products_id"];
63 $rc=query("shop",$sql,"insartikel");
64 $sql="insert into products_description (products_id,language_id,products_name) values (".$rs[0]["products_id"].",$defLang,' ')";
65 $rc=query("shop",$sql,"insartikel");
66 $sql="insert into products_to_categories (products_id,categories_id) values (".$rs[0]["products_id"].",".$data["categories_id"].")";
67 $rc=query("shop",$sql,"insartikel");
68 echo " <b>insert</b> ";
69 updartikel($data,$rs[0]["products_id"]);
71 function updartikel($data,$id) {
72 global $header,$tax,$defLang;
73 $sql="update products set products_price=%01.2f,products_weight=%01.2f,products_tax_class_id=%d,products_last_modified=now() where products_id=%d";
74 $sql=sprintf($sql,$data[array_search("products_price",$header)],$data[array_search("products_weight",$header)],$tax[$data[array_search("products_tax",$header)]],$id);
75 $rc=query("shop",$sql,"updartikel");
76 $sql="update products_description set products_name='%s',products_description='%s' where products_id=%d and language_id=$defLang";
77 $sql=sprintf($sql,$data[array_search("products_name",$header)],$data[array_search("products_description",$header)],$id);
78 $rc=query("shop",$sql,"insartikel");
79 $sql="update products_to_categories set categories_id=".$data[array_search("categories_id",$header)]." where products_id=$id";
80 $rc=query("shop",$sql,"insartikel");
81 echo "(".$id." ".$data[array_search("products_name",$header)].")+++<br>";
83 function chkartikel($data) {
85 $sql="select * from products P left join products_description D on P.products_id=D.products_id left join products_to_categories C on P.products_id=C.products_id where products_model like '".$data[array_search("products_model",$header)]."' and language_id=2";
86 $rs=getAll("shop",$sql,"chkartikel");
88 if ($rs[0]["products_price"]<>$data[array_search("products_price",$header)]) { updartikel($data,$rs[0]["products_id"]); }
89 else if ($rs[0]["products_weight"]<>$data[array_search("products_weight",$header)]) { updartikel($data,$rs[0]["products_id"]); }
90 else if ($rs[0]["products_name"]<>$data[array_search("products_name",$header)]) { updartikel($data,$rs[0]["products_id"]); }
91 else if ($rs[0]["products_description"]<>$data[array_search("products_description",$header)]) { updartikel($data,$rs[0]["products_id"]); }
92 else if ($rs[0]["products_tax_class_id"]<>$tax[$data[array_search("products_tax",$header)]]) { updartikel($data,$rs[0]["products_id"]); }
93 else if ($rs[0]["categories_id"]<>$data[array_search("categories_id",$header)]) { updartikel($data,$rs[0]["products_id"]); }
94 else { echo "(".$rs[0]["products_id"]." ".$rs[0]["products_name"].")...<br>"; };
100 $sql="select languages_id from languages";
101 $rs=getAll("shop",$sql,"sellanguageid");
103 foreach ($rs as $zeile) {
104 $langs[]=$zeile["languages_id"];
109 $sql="select * from languages L left join configuration C on L.code=C.configuration_value where configuration_key = 'DEFAULT_LANGUAGE'";
110 $rs=getAll("shop",$sql,"sellanguage");
112 $defLang=$rs[0]["languages_id"];
116 $sql="select * from tax_rates";
117 $rs=getAll("shop",$sql,"taxrates");
119 foreach ($rs as $zeile) {
120 $tax[$zeile["tax_rate"]]=$zeile["tax_class_id"];
126 if ($_FILES["csv"]["name"] || ($_POST["nofile"] && file_exists($SHOPdir)) ) {
127 if ($_FILES["csv"]["tmp_name"]) {
128 move_uploaded_file($_FILES["csv"]["tmp_name"],$SHOPdir);
130 $f=fopen($SHOPdir,"r");
131 $header=fgetcsv($f,1000,";");
132 $header[]="categories_id";
133 $data=fgetcsv($f,1000,";");
135 $catId=getCategory($data[array_search("categories_name",$header)]);
138 $data=fgetcsv($f,1000,";");
141 echo "<a href='trans.php'>zurück</a>";
146 <title>Datenaustausch ERP-xt:Commerce</title>
151 <h1>Artikelimport aus csv-Datei in xt:Commerce</h1><br>
152 <form name="csv" action="shopimport_csv.php" enctype="multipart/form-data" method="post">
153 <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="500000">
154 <input type="checkbox" name="nofile" value="1">Auf dem Server vorhandene Daten importieren<br>
155 Datenfile für Import <input type="file" name="csv"><br>
156 <input type="submit" name="ok" value="ok">
159 <a href="trans.php">zurück</a>