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