OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
oximex.php
Go to the documentation of this file.
1 <?php
2 
7 class oxImex extends oxBase
8 {
9 
19  public function exportLexwareArticles($iStart, $iLines, $sFilepath)
20  {
21  $myConfig = $this->getConfig();
22  $oDb = oxDb::getDb();
23 
24  $sArticleTable = getViewName('oxarticles');
25 
26  $sSelect = "select count(oxid) from $sArticleTable ";
27  $iSize = (int) $oDb->getOne($sSelect);
28 
29  if ($iStart < $iSize) {
30  $fp = fopen($sFilepath, "ab");
31  if (!$iStart) {
32  // first time, write header
33  fwrite($fp, "\"Artikelnummer\";\"Bezeichnung\";\"Einheit\";\"Gewicht\";\"Matchcode\";\"Preis pro Anzahl\";\"Warengruppe\";\"Warengr.-Kurzbez.\";\"Warengr.-Steuersatz\";\"Warengr.-Konto Inland\";\"Warengr.-Konto Ausland\";\"Warengr.-Konto EG\";\"Preis 1\";\"Preis 2\";\"Preis 3\";\"Preis I/1\";\"Preis I/2\";\"Preis I/3\";\"Preis II/1\";\"Preis II/2\";\"Preis II/3\";\"Preis III/1\";\"Preis III/2\";\"Preis III/3\";\"B/N\";\"Lagerartikel\";\"EK 1\";\"W�hrung EK1\";\"EK 2\";\"W�hrung EK2\";\"Staffelmenge 1\";\"Staffelmenge 2\";\"Staffelmenge 3\";\"Lieferantennummer 1\";\"Lieferantennummer 2\";\"Bestellmenge Lf.1\";\"Bestellmenge Lf.2\";\"Bestellnr. Lf.1\";\"Bestellnr. Lf.2\";\"Lieferzeit Lf.1\";\"Lieferzeit Lf.2\";\"Lagerbestand\";\"Mindestbestand\";\"Lagerort\";\"Bestellte Menge\";\"St�ckliste\";\"Internet\";\"Text\"\r\n");
34  }
35  $oldMode = $oDb->setFetchMode(oxDb::FETCH_MODE_ASSOC);
36  $sSelect = "select * from $sArticleTable ";
37  $rs = $oDb->selectLimit($sSelect, $iLines, $iStart);
38  $oDb->setFetchMode($oldMode);
39 
40  while (!$rs->EOF) {
41  $oArticle = oxNew("oxarticle");
42  $blAdmin = $this->isAdmin();
43  // TODO: this place could be optimized. please check what we can do.
44  $this->setAdminMode(false);
45  $oArticle->load($rs->fields['OXID']);
46  $this->setAdminMode($blAdmin);
47 
48  $sSelect = "select oxtitle from " . $oArticle->getViewName() . " where oxid = " . $oDb->quote($oArticle->oxarticles__oxparentid->value);
49  $oTitle = $oDb->getOne($sSelect);
50  if ($oTitle != false && strlen($oTitle)) {
51  $nTitle = $this->interForm($oTitle);
52  } else {
53  $nTitle = $this->interForm($oArticle->oxarticles__oxtitle->value);
54  }
55 
56 
57  $sToFile = $oArticle->oxarticles__oxartnum->value // Artikelnummer
58  //.";".$this->interForm($oArticle->oxarticles__oxshortdesc->value." ".$oArticle->oxarticles__oxvarselect->value) // Bezeichnung
59  . ";" . $nTitle . " " . $this->interForm($oArticle->oxarticles__oxvarselect->value) // Bezeichnung
60  . ";" . "Stueck" // Einheit
61  . ";" . $oArticle->oxarticles__oxweight->value // Gewicht
62  . ";" . $oArticle->oxarticles__oxartnum->value // Matchcode
63  . ";" . "1,000" // Preis pro Anzahl
64  . ";" // Warengruppe
65  . ";" // Warengr.-Kurzbez.
66  . ";" // Warengr.-Steuersatz
67  . ";" // Warengr.-Konto Inland
68  . ";" // Warengr.-Konto Ausland
69  . ";" // Warengr.-Konto EG
70  . ";" . number_format($oArticle->oxarticles__oxprice->value, 2, '.', '') // Preis 1
71  . ";" // Preis 2
72  . ";" // Preis 3
73  . ";" // Preis I/1
74  . ";" // Preis I/2
75  . ";" // Preis I/3
76  . ";" // Preis II/1
77  . ";" // Preis II/2
78  . ";" // Preis II/3
79  . ";" // Preis III/1
80  . ";" // Preis III/2
81  . ";" // Preis III/3
82  . ";" // B/N
83  . ";" // Lagerartikel
84  //.";".number_format($oArticle->oxarticles__oxtprice->value, 2, '.', '')// EK 1
85  // #343 fix
86  . ";" . number_format($oArticle->oxarticles__oxbprice->value, 2, '.', '') // EK 1
87  . ";" // W�hrung EK1
88  . ";" // EK 2
89  . ";" // W�hrung EK2
90  . ";" // Staffelmenge 1
91  . ";" // Staffelmenge 2
92  . ";" // Staffelmenge 3
93  . ";" // Lieferantennummer 1
94  . ";" // Lieferantennummer 2
95  . ";" // Bestellmenge Lf.1
96  . ";" // Bestellmenge Lf.2
97  . ";" // Bestellnr. Lf.1
98  . ";" // Bestellnr. Lf.2
99  . ";" // Lieferzeit Lf.1
100  . ";" // Lieferzeit Lf.2
101  . ";" . $oArticle->oxarticles__oxstock->value // Lagerbestand
102  . ";" // Mindestbestand
103  . ";" // Lagerort
104  . ";" // Bestellte Menge
105  . ";" // St�ckliste
106  . ";1" // Internet
107  . ";" . $this->interForm($oArticle->oxarticles__oxshortdesc->value . $oArticle->getLongDesc()) // Text
108  . ";";
109  $sToFile .= "\r\n";
110 
111  fwrite($fp, $sToFile);
112  $rs->moveNext();
113  }
114 
115  fclose($fp);
116 
117  return true;
118  }
119 
120  return false;
121 
122  }
123 
131  public function interFormSimple($nValue)
132  {
133  $nValue = str_replace("\r", "", $nValue);
134  $nValue = str_replace("\n", " ", $nValue);
135  $nValue = str_replace('"', '""', $nValue);
136 
137  return $nValue;
138  }
139 
149  public function interForm($nValue, $oObj = null)
150  { // thnx to Volker D�rk for this function and his help here
151 
152  // #387A skipping conversion for fields where info must be passed in original format
153  $aFieldTypesToSkip = array("text", "oxshortdesc", "oxlongdesc");
154  $blSkipStrpTags = false;
155  if ($oObj != null) {
156  // using object field "fldtype", to skip processing because usually
157  // this type of field is used for HTML text
158  //
159  // you may change field to "fldname" and add to $aFieldTypesToSkip
160  // "oxlongdesc" value to skip only longdesc field
161  //
162  if (in_array($oObj->fldtype, $aFieldTypesToSkip) || in_array($oObj->fldname, $aFieldTypesToSkip)) {
163  $blSkipStripTags = true;
164  }
165  }
166 
167  //removing simple & (and not &uuml; chars)
168  //(not full just a simple check for existing customers for cases like Johnson&Johnson)
169 
170  $oStr = getStr();
171  if ($oStr->strpos($nValue, "&") !== false && $oStr->strpos($nValue, ";") == false) {
172  $nValue = str_replace("&", "&amp;", $nValue);
173  }
174 
175  $nValue = str_replace("&nbsp;", " ", $nValue);
176  $nValue = str_replace("&auml;", "�", $nValue);
177  $nValue = str_replace("&ouml;", "�", $nValue);
178  $nValue = str_replace("&uuml;", "�", $nValue);
179  $nValue = str_replace("&Auml;", "�", $nValue);
180  $nValue = str_replace("&Ouml;", "�", $nValue);
181  $nValue = str_replace("&Uuml;", "�", $nValue);
182  $nValue = str_replace("&szlig;", "�", $nValue);
183 
184  // usually & symbol goes (or should go) like that:
185  // "& text...", so we predict that this is a rule
186  // and replace it with special HTML code
187  $nValue = str_replace("& ", "&amp; ", $nValue);
188 
189  $nValue = str_replace("\"", "'", $nValue);
190  $nValue = str_replace("(", "'", $nValue);
191  $nValue = str_replace(")", "'", $nValue);
192  $nValue = str_replace("\r\n", "", $nValue);
193  $nValue = str_replace("\n", "", $nValue);
194 
195  if (!$blSkipStripTags) {
196  $nValue = strip_tags($nValue);
197  }
198 
199  return $nValue;
200  }
201 
209  public function internPrice($nPrice)
210  { // thnx to Volker D�rk for this function and his help here
211  $nPrice = $this->interForm($nPrice);
212  $nPrice = number_format((double) $nPrice, 2, '.', '');
213 
214  return $nPrice;
215  }
216 
225  public function exportLexwareOrders($iFromOrderNr = "", $iToOrderNr = "")
226  {
227  // thnx to Volker D�rk for this function and his help here
228  $myConfig = $this->getConfig();
229 
230  $sNewLine = "\r\n";
231 
232  $sSelect = "select * from oxorder where 1 ";
233 
234  if ($iFromOrderNr !== "") {
235  $iFromOrderNr = (int) $iFromOrderNr;
236  $sSelect .= "and oxordernr >= $iFromOrderNr ";
237  }
238 
239  if ($iToOrderNr !== "") {
240  $iToOrderNr = (int) $iToOrderNr;
241  $sSelect .= "and oxordernr <= $iToOrderNr ";
242  }
243 
244  $oOrderlist = oxNew("oxlist");
245  $oOrderlist->init("oxorder");
246  $oOrderlist->selectString($sSelect);
247 
248  if (!$oOrderlist->count()) {
249  return null;
250  }
251 
252  $sCharset = $this->_getCharset();
253 
254  $sExport = "<?xml version=\"1.0\" encoding=\"{$sCharset}\"?>$sNewLine";
255  $sExport .= "<Bestellliste>$sNewLine";
256  $sRet = $sExport;
257 
258  foreach ($oOrderlist as $oOrder) {
259  // Convert each amount of money with currency rate of the order
260  $dOrderCurRate = (double) $oOrder->oxorder__oxcurrate->value;
261 
262  $oUser = oxNew("oxuser");
263  $oUser->load($oOrder->oxorder__oxuserid->value);
264 
265  $sExport = "<Bestellung " . $this->_convertStr("zur�ckgestellt") . "=\"Nein\" bearbeitet=\"Nein\" " . $this->_convertStr("�bertragen") . "=\"Nein\">$sNewLine";
266  $sExport .= "<Bestellnummer>" . $oOrder->oxorder__oxordernr->value . "</Bestellnummer>$sNewLine";
267  $sExport .= "<Rechnungsnummer>" . $oOrder->oxorder__oxbillnr->value . "</Rechnungsnummer>$sNewLine";
268  $sExport .= "<Standardwaehrung>978</Standardwaehrung>$sNewLine";
269  $sExport .= "<Bestelldatum>$sNewLine";
270  $sDBDate = oxRegistry::get("oxUtilsDate")->formatDBDate($oOrder->oxorder__oxorderdate->value);
271  $sExport .= "<Datum>" . substr($sDBDate, 0, 10) . "</Datum>$sNewLine";
272  $sExport .= "<Zeit>" . substr($sDBDate, 11, 8) . "</Zeit>$sNewLine";
273  $sExport .= "</Bestelldatum>$sNewLine";
274  $sExport .= "<Kunde>$sNewLine";
275 
276  $sExport .= "<Kundennummer>" . /*$this->interForm($oUser->oxuser__oxcustnr->value).*/
277  "</Kundennummer>$sNewLine";
278  $sExport .= "<Firmenname>" . $this->interForm($oOrder->oxorder__oxbillcompany->value) . "</Firmenname>$sNewLine";
279  $sExport .= "<Anrede>" . $this->interForm(oxRegistry::getLang()->translateString($oOrder->oxorder__oxbillsal->value)) . "</Anrede>$sNewLine";
280  $sExport .= "<Vorname>" . $this->interForm($oOrder->oxorder__oxbillfname->value) . "</Vorname>$sNewLine";
281  $sExport .= "<Name>" . $this->interForm($oOrder->oxorder__oxbilllname->value) . "</Name>$sNewLine";
282  $sExport .= "<Strasse>" . $this->interForm($oOrder->oxorder__oxbillstreet->value) . " " . $this->interForm($oOrder->oxorder__oxbillstreetnr->value) . "</Strasse>$sNewLine";
283  $sExport .= "<PLZ>" . $this->interForm($oOrder->oxorder__oxbillzip->value) . "</PLZ>$sNewLine";
284  $sExport .= "<Ort>" . $this->interForm($oOrder->oxorder__oxbillcity->value) . "</Ort>$sNewLine";
285  $sExport .= "<Bundesland>" . "" . "</Bundesland>$sNewLine";
286  $sExport .= "<Land>" . $this->interForm($oOrder->oxorder__oxbillcountry->value) . "</Land>$sNewLine";
287  $sExport .= "<Email>" . $this->interForm($oOrder->oxorder__oxbillemail->value) . "</Email>$sNewLine";
288  $sExport .= "<Telefon>" . $this->interForm($oOrder->oxorder__oxbillfon->value) . "</Telefon>$sNewLine";
289  $sExport .= "<Telefon2>" . $this->interForm($oUser->oxuser__oxprivfon->value) . "</Telefon2>$sNewLine";
290  $sExport .= "<Fax>" . $this->interForm($oOrder->oxorder__oxbillfax->value) . "</Fax>$sNewLine";
291 
292  $sDelComp = "";
293  $sDelfName = "";
294  $sDellName = "";
295  $sDelStreet = "";
296  $sDelZip = "";
297  $sDelCity = "";
298  $sDelCountry = "";
299 
300  // lieferadresse
301  if ($oOrder->oxorder__oxdellname->value) {
302  $sDelComp = $oOrder->oxorder__oxdelcompany->value;
303  $sDelfName = $oOrder->oxorder__oxdelfname->value;
304  $sDellName = $oOrder->oxorder__oxdellname->value;
305  $sDelStreet = $oOrder->oxorder__oxdelstreet->value . " " . $oOrder->oxorder__oxdelstreetnr->value;
306  $sDelZip = $oOrder->oxorder__oxdelzip->value;
307  $sDelCity = $oOrder->oxorder__oxdelcity->value;
308  $sDelCountry = $oOrder->oxorder__oxdelcountry->value;
309  }
310 
311  $sExport .= "<Lieferadresse>$sNewLine";
312  $sExport .= "<Firmenname>" . $this->interForm($sDelComp) . "</Firmenname>$sNewLine";
313  $sExport .= "<Vorname>" . $this->interForm($sDelfName) . "</Vorname>$sNewLine";
314  $sExport .= "<Name>" . $this->interForm($sDellName) . "</Name>$sNewLine";
315  $sExport .= "<Strasse>" . $this->interForm($sDelStreet) . "</Strasse>$sNewLine";
316  $sExport .= "<PLZ>" . $this->interForm($sDelZip) . "</PLZ>$sNewLine";
317  $sExport .= "<Ort>" . $this->interForm($sDelCity) . "</Ort>$sNewLine";
318  $sExport .= "<Bundesland>" . "" . "</Bundesland>$sNewLine";
319  $sExport .= "<Land>" . $this->interForm($sDelCountry) . "</Land>$sNewLine";
320  $sExport .= "</Lieferadresse>$sNewLine";
321  $sExport .= "<Matchcode>" . $this->interForm($oOrder->oxorder__oxbilllname->value) . ", " . $this->interForm($oOrder->oxorder__oxbillfname->value) . "</Matchcode>$sNewLine";
322 
323  // ermitteln ob steuerbar oder nicht
324  $sCountry = strtolower($oUser->oxuser__oxcountryid->value);
325  $aHomeCountry = $myConfig->getConfigParam('aHomeCountry');
326  $sSteuerbar = (is_array($aHomeCountry) && in_array($sCountry, $aHomeCountry)) ? "ja" : "nein";
327 
328  $sExport .= "<fSteuerbar>" . $this->interForm($sSteuerbar) . "</fSteuerbar>$sNewLine";
329  $sExport .= "</Kunde>$sNewLine";
330  $sExport .= "<Artikelliste>$sNewLine";
331  $sRet .= $sExport;
332 
333  $dSumNetPrice = 0;
334  $dSumBrutPrice = 0;
335 
336  $oOrderArticles = $oOrder->getOrderArticles(true);
337  foreach ($oOrderArticles as $oOrderArt) {
338 
339  $dVATSet = array_search($oOrderArt->oxorderarticles__oxvat->value, $myConfig->getConfigParam('aLexwareVAT'));
340  $sExport = " <Artikel>$sNewLine";
341  //$sExport .= " <Artikelzusatzinfo><Nettostaffelpreis>".$this->InternPrice( $oOrderArt->oxorderarticles__oxnetprice->value)."</Nettostaffelpreis></Artikelzusatzinfo>$sNewLine";
342  $sExport .= " <Artikelzusatzinfo><Nettostaffelpreis></Nettostaffelpreis></Artikelzusatzinfo>$sNewLine";
343  $sExport .= " <SteuersatzID>" . $dVATSet . "</SteuersatzID>$sNewLine";
344  $sExport .= " <Steuersatz>" . $this->internPrice($oOrderArt->oxorderarticles__oxvat->value / 100) . "</Steuersatz>$sNewLine";
345  $sExport .= " <Artikelnummer>" . $oOrderArt->oxorderarticles__oxartnum->value . "</Artikelnummer>$sNewLine";
346  $sExport .= " <Anzahl>" . $oOrderArt->oxorderarticles__oxamount->value . "</Anzahl>$sNewLine";
347  $sExport .= " <Produktname>" . $this->interForm($oOrderArt->oxorderarticles__oxtitle->value);
348  if ($oOrderArt->oxorderarticles__oxselvariant->value) {
349  $sExport .= "/" . $oOrderArt->oxorderarticles__oxselvariant->value;
350  }
351  $sExport .= " </Produktname>$sNewLine";
352  $sExport .= " <Rabatt>0.00</Rabatt>$sNewLine";
353 
354  $dUnitPrice = $oOrderArt->oxorderarticles__oxbrutprice->value / $oOrderArt->oxorderarticles__oxamount->value;
355  if ($dOrderCurRate > 0) {
356  $dUnitPrice /= $dOrderCurRate;
357  }
358  $sExport .= " <Preis>" . $this->internPrice($dUnitPrice) . "</Preis>$sNewLine";
359  $sExport .= " </Artikel>$sNewLine";
360  $sRet .= $sExport;
361 
362  $dSumNetPrice += $oOrderArt->oxorderarticles__oxnetprice->value;
363  $dSumBrutPrice += $oOrderArt->oxorderarticles__oxbrutprice->value;
364  }
365 
366  $dDiscount = $oOrder->oxorder__oxvoucherdiscount->value + $oOrder->oxorder__oxdiscount->value;
367  $dDelCost = $oOrder->oxorder__oxdelcost->value;
368  $dPaymentCost = $oOrder->oxorder__oxpaycost->value;
369  if ($dOrderCurRate > 0) {
370  $dDiscount /= $dOrderCurRate;
371  $dSumNetPrice /= $dOrderCurRate;
372  $dDelCost /= $dOrderCurRate;
373  $dSumBrutPrice /= $dOrderCurRate;
374  $dPaymentCost /= $dOrderCurRate;
375  }
376  $sExport = "<GesamtRabatt>" . $this->internPrice($dDiscount) . "</GesamtRabatt>$sNewLine";
377  $sExport .= "<GesamtNetto>" . $this->internPrice($dSumNetPrice) . "</GesamtNetto>$sNewLine";
378  $sExport .= "<Lieferkosten>" . $this->internPrice($dDelCost) . "</Lieferkosten>$sNewLine";
379  $sExport .= "<Zahlungsartkosten>" . $this->internPrice($dPaymentCost) . "</Zahlungsartkosten>$sNewLine";
380  $sExport .= "<GesamtBrutto>" . $this->internPrice($dSumBrutPrice) . "</GesamtBrutto>$sNewLine";
381  $sExport .= "<Bemerkung>" . strip_tags($oOrder->oxorder__oxremark->value) . "</Bemerkung>$sNewLine";
382  $sRet .= $sExport;
383 
384  $sExport = "</Artikelliste>$sNewLine";
385 
386  $sExport .= "<Zahlung>$sNewLine";
387  $oPayment = oxNew("oxpayment");
388  $oPayment->load($oOrder->oxorder__oxpaymenttype->value);
389 
390  $sExport .= "<Art>" . $oPayment->oxpayments__oxdesc->value . "</Art>$sNewLine";
391  $sExport .= "</Zahlung>$sNewLine";
392 
393  $sExport .= "</Bestellung>$sNewLine";
394  $sRet .= $sExport;
395 
396  $oOrder->oxorder__oxexport->setValue(1);
397  $oOrder->save();
398  }
399  $sExport = "</Bestellliste>$sNewLine";
400  $sRet .= $sExport;
401 
402  return $sRet;
403  }
404 
410  protected function _getCharset()
411  {
412  return oxRegistry::getLang()->translateString('charset');
413  }
414 
422  protected function _convertStr($sStr)
423  {
424  $sCharset = $this->_getCharset();
425 
426  if ($sCharset == 'ISO-8859-15') {
427  return $sStr;
428  }
429 
430  return $sStr = iconv('ISO-8859-15', $sCharset, $sStr);
431  }
432 }