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