From 5539c9849c5a1ede1a262e63ac70d7ca473d55cc Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sat, 28 Jan 2023 13:04:28 +0100 Subject: [PATCH 01/12] Presta shopimporter --- www/lib/class.remote.php | 18 +- www/pages/appstore.php | 8 +- www/pages/shopimporter_presta.php | 417 ++++++++++++++++++++++++++++++ 3 files changed, 434 insertions(+), 9 deletions(-) create mode 100644 www/pages/shopimporter_presta.php diff --git a/www/lib/class.remote.php b/www/lib/class.remote.php index 8fa23b2c..05d71eec 100644 --- a/www/lib/class.remote.php +++ b/www/lib/class.remote.php @@ -1,4 +1,4 @@ - +*/ +?> app->erp->CreateDatei($path_parts['basename'], 'Shopbild', '', '', base64_decode($v['content']), 'Cronjob'); + $tmpfilename = tempnam($this->app->erp->GetTMP(), 'img'); + file_put_contents($tmpfilename, base64_decode($v['content'])); + $fileid = $this->app->erp->CreateDatei($path_parts['basename'], 'Shopbild', '', '', $tmpfilename, 'Cronjob'); $this->app->erp->AddDateiStichwort($fileid, 'Shopbild', 'artikel', $articleid); + if (@is_file($tmpfilename)) + unlink($tmpfilename); } } }elseif($dateien[0]['subjekt'] === 'shopbild'){ @@ -766,12 +770,16 @@ class Remote if($v['path'] != '' && $v['content'] != '') { $path_parts = pathinfo($v['path']); - $fileid = $this->app->erp->CreateDatei($path_parts['basename'], 'Shopbild', '', '', base64_decode($v['content']), 'Cronjob'); + $tmpfilename = tempnam($this->app->erp->GetTMP(), 'img'); + file_put_contents($tmpfilename, base64_decode($v['content'])); + $fileid = $this->app->erp->CreateDatei($path_parts['basename'], 'Shopbild', '', '', $tmpfilename, 'Cronjob'); if(isset($v['id'])) { $this->ShopexportMappingSet($id, 'datei', $fileid, $v['id'], $articleid); } $this->app->erp->AddDateiStichwort($fileid, 'Shopbild', 'artikel', $articleid); + if (@is_file($tmpfilename)) + unlink($tmpfilename); } } } diff --git a/www/pages/appstore.php b/www/pages/appstore.php index ad3f857b..5ada3d28 100644 --- a/www/pages/appstore.php +++ b/www/pages/appstore.php @@ -1,4 +1,4 @@ - +*/ +?> array('Bezeichnung'=>'Presta', 'Link'=>'index.php?module=onlineshops&action=create&cmd=shopimporter_presta', 'Icon'=>'Icons_dunkel_1.gif', - 'Versionen'=>'ENT','install'=>true, 'beta' => false,'kategorie'=>'{|Shop Schnittstelle|}') + 'Versionen'=>'ALL','install'=>true, 'beta' => false,'kategorie'=>'{|Shop Schnittstelle|}') ,'shopimporter_shopify'=>array( 'Bezeichnung'=>'Shopify API Advanced', 'Link'=>'index.php?module=onlineshops&action=create&cmd=shopimporter_shopify', diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php new file mode 100644 index 00000000..7ee9eae2 --- /dev/null +++ b/www/pages/shopimporter_presta.php @@ -0,0 +1,417 @@ + 'de', 1 => 'en']; + private $taxationByDestinationCountry; + + + public function __construct($app, $intern = false) + { + $this->app = $app; + $this->intern = $intern; + if ($intern) + return; + + } + + public function EinstellungenStruktur() + { + return [ + 'ausblenden' => ['abholmodus' => ['ab_nummer', 'zeitbereich']], + 'functions' => ['getarticlelist'], + 'felder' => [ + 'protokoll' => [ + 'typ' => 'checkbox', + 'bezeichnung' => '{|Protokollierung im Logfile|}:' + ], + 'textekuerzen' => [ + 'typ' => 'checkbox', + 'bezeichnung' => '{|Texte bei Artikelexport auf Maximallänge kürzen|}:' + ], + 'useKeyAsParameter' => [ + 'typ' => 'checkbox', + 'bezeichnung' => '{|Shop Version ist mindestens 1.6.1.1|}:' + ], + 'apikey' => [ + 'typ' => 'text', + 'bezeichnung' => '{|API Key|}:', + 'size' => 40, + ], + 'shopurl' => [ + 'typ' => 'text', + 'bezeichnung' => '{|Shop URL|}:', + 'size' => 40, + ], + 'shopidpresta' => [ + 'typ' => 'text', + 'bezeichnung' => '{|Shop ID des Shops|}:', + 'size' => 40, + ], + 'steuergruppen' => [ + 'typ' => 'text', + 'bezeichnung' => '{|Steuergruppenmapping|}:', + 'size' => 40, + ], + 'zustand' => [ + 'typ' => 'text', + 'bezeichnung' => '{|Freifeld Zustand|}:', + 'size' => 40, + ], + 'abholen' => [ + 'typ' => 'text', + 'bezeichnung' => '{|\'Abholen\' Status IDs|}:', + 'size' => 40, + ], + 'bearbeitung' => [ + 'typ' => 'text', + 'bezeichnung' => '{|\'In Bearbeitung\' Status IDs|}:', + 'size' => 40, + ], + 'abgeschlossen' => [ + 'typ' => 'text', + 'bezeichnung' => '{|\'Abgeschlossen\' Status IDs|}:', + 'size' => 40, + ], + 'autoerstellehersteller' => [ + 'typ' => 'checkbox', + 'bezeichnung' => '{|Fehlende Hersteller automatisch anlegen|}:', + 'col' => 2 + ], + 'zeigezustand' => [ + 'typ' => 'checkbox', + 'bezeichnung' => '{|Artikelzustand im Shop anzeigen|}:', + 'col' => 2 + ], + 'zeigepreis' => [ + 'typ' => 'checkbox', + 'bezeichnung' => '{|Artikelpreis im Shop anzeigen|}:', + 'col' => 2 + ], + ] + ]; + } + + public function getKonfig($shopid, $data) + { + $this->shopid = $shopid; + $this->data = $data; + $importerSettings = $this->app->DB->SelectArr("SELECT `einstellungen_json` FROM `shopexport` WHERE `id` = '$shopid' LIMIT 1"); + $importerSettings = reset($importerSettings); + + $einstellungen = []; + if (!empty($importerSettings['einstellungen_json'])) { + $einstellungen = json_decode($importerSettings['einstellungen_json'], true); + } + $this->protocol = $einstellungen['felder']['protokoll']; + $this->apiKey = $einstellungen['felder']['apikey']; + $this->shopUrl = rtrim($einstellungen['felder']['shopurl'], '/') . '/'; + if ($einstellungen['felder']['autoerstellehersteller'] === '1') { + $this->createManufacturerAllowed = true; + } + $this->idsabholen = $einstellungen['felder']['abholen']; + $this->idbearbeitung = $einstellungen['felder']['bearbeitung']; + $this->idabgeschlossen = $einstellungen['felder']['abgeschlossen']; + $query = sprintf('SELECT `steuerfreilieferlandexport` FROM `shopexport` WHERE `id` = %d', $this->shopid); + $this->taxationByDestinationCountry = !empty($this->app->DB->Select($query)); + } + + public function ImportAuth() { + $ch = curl_init($this->shopUrl); + curl_setopt($ch, CURLOPT_USERNAME, $this->apiKey); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); + if ($code == 200) + return 'success'; + + return $response; + } + + public function ImportDeleteAuftrag() + { + $auftrag = $this->data['auftrag']; + + $obj = $this->prestaRequest('GET', 'order_histories?schema=blank'); + $obj->order_history->id_order = $auftrag; + $obj->order_history->id_order_state = $this->idbearbeitung; + + $this->prestaRequest('POST', 'order_histories', $obj->asXML()); + } + + public function ImportUpdateAuftrag() + { + $auftrag = $this->data['auftrag']; + + $obj = $this->prestaRequest('GET', 'order_histories?schema=blank'); + $obj->order_history->id_order = $auftrag; + $obj->order_history->id_order_state = $this->idabgeschlossen; + + $this->prestaRequest('POST', 'order_histories', $obj->asXML()); + + //TODO Tracking + } + + public function ImportGetAuftraegeAnzahl() + { + $ordersToProcess = $this->getOrdersToProcess($this->getOrderSearchLimit()); + return count($ordersToProcess); + } + + public function ImportGetAuftrag() + { + $voucherArticleId = $this->app->DB->Select("SELECT s.artikelrabatt FROM `shopexport` AS `s` WHERE s.id='$this->shopid' LIMIT 1"); + $voucherArticleNumber = $this->app->DB->Select("SELECT a.nummer FROM `artikel` AS `a` WHERE a.id='$voucherArticleId' LIMIT 1"); + + if (empty($this->idsabholen)) { + return false; + } + $expectOrderArray = !empty($this->data['anzgleichzeitig']) && (int)$this->data['anzgleichzeitig'] > 1; + $expectNumber = !empty($this->data['nummer']); + if ($expectNumber) { + $ordersToProcess = [$this->data['nummer']]; + } elseif (!$expectOrderArray) { + $ordersToProcess = $this->getOrdersToProcess(1); + } else { + $ordersToProcess = $this->getOrdersToProcess($this->getOrderSearchLimit()); + } + + $fetchedOrders = []; + foreach ($ordersToProcess as $currentOrderId) { + $this->Log("Importing order from presta", [$this->data, $ordersToProcess, $currentOrderId]); + $order = $this->prestaRequest('GET', "orders/$currentOrderId"); + $order = $order->order; + $cart = []; + $cart['zeitstempel'] = strval($order->date_add); + $cart['auftrag'] = strval($order->id); + $cart['onlinebestellnummer'] = strval($order->reference); + $cart['gesamtsumme'] = strval($order->total_paid); + $cart['versandkostenbrutto'] = strval($order->total_shipping); + $cart['bestelldatum'] = strval($order->date_add); + + $carrier = $this->prestaRequest('GET', "carriers/$order->id_carrier"); + $cart['lieferung'] = strval($carrier->name); + + $customer = $this->prestaRequest('GET', "customers/$order->id_customer"); + $cart['email'] = strval($customer->email); + + $invoiceAddress = $this->prestaRequest('GET', "addresses/$order->id_address_invoice"); + $invoiceAddress = $invoiceAddress->address; + $invoiceCountry = $this->prestaRequest('GET', "countries/$invoiceAddress->id_country"); + $invoiceCountry = $invoiceCountry->country; + $cart['name'] = "$invoiceAddress->firstname $invoiceAddress->lastname"; + if (!empty($invoiceAddress->company)) { + $cart['ansprechpartner'] = $cart['name']; + $cart['name'] = strval($invoiceAddress->company); + } + $cart['strasse'] = strval($invoiceAddress->address1); + $cart['adresszusatz'] = strval($invoiceAddress->address2); + $cart['telefon'] = strval($invoiceAddress->phone_mobile); + if (empty($cart['telefon'])) + $cart['telefon'] = strval($invoiceAddress->phone); + $cart['plz'] = strval($invoiceAddress->postcode); + $cart['ort'] = strval($invoiceAddress->city); + $cart['ustid'] = strval($invoiceAddress->vat_number); + $cart['land'] = strval($invoiceCountry->iso_code); + + if ($order->id_address_invoice != $order->id_address_delivery) { + $deliveryAddress = $this->prestaRequest('GET', "addresses/$order->id_address_delivery"); + $deliveryAddress = $deliveryAddress->address; + $deliveryCountry = $this->prestaRequest('GET', "countries/$deliveryAddress->id_country"); + $deliveryCountry = $deliveryCountry->country; + $cart['abweichendelieferadresse'] = 1; + $cart['lieferadresse_name'] = "$deliveryAddress->firstname $deliveryAddress->lastname"; + if (!empty($deliveryAddress->company)) { + $cart['lieferadresse_ansprechpartner'] = $cart['lieferadresse_name']; + $cart['lieferadresse_name'] = strval($deliveryAddress->company); + } + $cart['lieferadresse_strasse'] = strval($deliveryAddress->address1); + $cart['lieferadresse_adresszusatz'] = strval($deliveryAddress->address2); + $cart['lieferadresse_plz'] = strval($deliveryAddress->postcode); + $cart['lieferadresse_ort'] = strval($deliveryAddress->city); + $cart['lieferadresse_land'] = strval($deliveryCountry->iso_code); + } + + //TODO + //$cart['transaktionsnummer'] + $cart['zahlungsweise'] = strval($order->payment); + + $taxedCountry = $cart['land']; + if (!empty($cart['lieferadresse_land']) && $this->taxationByDestinationCountry) { + $taxedCountry = $cart['lieferadresse_land']; + } + if (strval($order->total_paid_tax_incl) === strval($order->total_paid_tax_excl)) { + if ($this->app->erp->IstEU($taxedCountry)) { + $cart['ust_befreit'] = 1; + } elseif ($this->app->erp->Export($taxedCountry)) { + $cart['ust_befreit'] = 2; + } else { + $cart['ust_befreit'] = 3; + } + } + + $cart['articlelist'] = []; + foreach ($order->associations->order_rows->order_row as $order_row) { + + $steuersatz = (strval($order_row->unit_price_tax_incl) / strval($order_row->unit_price_tax_excl)) - 1; + $steuersatz = round($steuersatz, 1); + + $cart['articlelist'][] = [ + 'articleid' => strval($order_row->product_reference), + 'name' => strval($order_row->product_name), + 'quantity' => strval($order_row->product_quantity), + 'price_netto' => strval($order_row->product_price), + 'steuersatz' => $steuersatz + ]; + } + + $fetchedOrders[] = [ + 'id' => $cart['auftrag'], + 'sessionid' => '', + 'logdatei' => '', + 'warenkorb' => base64_encode(serialize($cart)), + 'warenkorbjson' => base64_encode(json_encode($cart)), + ]; + } + $this->Log('Precessed order from presta', $fetchedOrders); + + return $fetchedOrders; + } + + public function ImportGetArticleList() + { + $result = []; + $response = $this->prestaRequest('GET', 'products?display=[reference]'); + foreach ($response->products->product as $product) { + $result[] = $product->reference; + } + + array_unique($result); + return $result; + } + + public function ImportGetArticle() + { + $nummer = $this->data['nummer']; + if (isset($this->data['nummerintern'])) { + $nummer = $this->data['nummerintern']; + } + $nummer = trim($nummer); + + if (empty($nummer)) + return; + + $searchresult = $this->prestaRequest('GET', 'products?filter[reference]='.$nummer); + if (empty($searchresult)) { + $this->Log('No product found in Shop', $this->data); + return; + } + if (count($searchresult->products->product) > 1) { + $this->Log('Got multiple results from Shop', $this->data); + } + + $productid = $searchresult->products->product->attributes()->id; + $product = $this->prestaRequest('GET', "products/$productid"); + $res = []; + $res['nummer'] = strval($product->product->reference); + $res['artikelnummerausshop'] = strval($product->product->reference); + $names = $this->toMultilangArray($product->product->name->language); + $descriptions = $this->toMultilangArray($product->product->description->language); + $shortdescriptions = $this->toMultilangArray($product->product->description_short->language); + $res['name'] = $names['de']; + $res['name_en'] = $names['en']; + $res['uebersicht_de'] = $descriptions['de']; + $res['uebersicht_en'] = $descriptions['en']; + $res['preis_netto'] = strval($product->product->price); + $res['hersteller'] = strval($product->product->manufacturer_name); + $res['ean'] = strval($product->product->ean13); + + $images = []; + foreach ($product->product->associations->images->image as $img) { + $endpoint = "images/products/$productid/$img->id"; + $imgdata = $this->prestaRequest('GET', $endpoint, '', true); + $images[] = [ + 'content' => base64_encode($imgdata), + 'path' => "$img->id.jpg", + 'id' => $img->id + ]; + } + $res['bilder'] = $images; + return $res; + } + + private function toMultilangArray($xmlnode) { + $res = []; + foreach ($xmlnode as $item) { + $iso = $this->langidToIso[strval($item->attributes()->id)]; + $res[$iso] = strval($item); + } + return $res; + } + + private function getOrdersToProcess(int $limit) + { + $states = implode('|', explode(',', $this->idsabholen)); + $response = $this->prestaRequest('GET', "orders?display=[id]&limit=$limit&filter[current_state]=[$states]"); + $result = []; + foreach ($response->orders->order as $order) { + $result[] = strval($order->id); + } + return $result; + } + + public function getOrderSearchLimit(): int + { + if(in_array($this->orderSearchLimit, ['50', '75', '100'])) { + return (int)$this->orderSearchLimit; + } + + return 25; + } + + private function Log($message, $dump = '') + { + if ($this->protocol) { + $this->app->erp->Logfile($message, print_r($dump, true)); + } + } + + private function prestaRequest($method, $endpoint, $data = '', $raw = false) + { + $url = $this->shopUrl . $endpoint; + $url = str_replace('[', '%5b', $url); + $url = str_replace(']', '%5d', $url); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + if (!empty($data)) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + } + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($ch, CURLOPT_USERNAME, $this->apiKey); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + if (curl_error($ch)) { + $this->error[] = curl_error($ch); + } + curl_close($ch); + + if ($raw) + return $response; + + return simplexml_load_string($response); + } +} \ No newline at end of file From d705d1a3eb76e8923166ec2382714d9615bea734 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 29 Jan 2023 00:56:37 +0100 Subject: [PATCH 02/12] Small bugfix in presta importer, improve steuersaetze.php --- www/pages/shopimporter_presta.php | 12 ++++++++++-- www/pages/steuersaetze.php | 10 +++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 7ee9eae2..69149240 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -203,10 +203,10 @@ class Shopimporter_Presta extends ShopimporterBase $cart['bestelldatum'] = strval($order->date_add); $carrier = $this->prestaRequest('GET', "carriers/$order->id_carrier"); - $cart['lieferung'] = strval($carrier->name); + $cart['lieferung'] = strval($carrier->carrier->name); $customer = $this->prestaRequest('GET', "customers/$order->id_customer"); - $cart['email'] = strval($customer->email); + $cart['email'] = strval($customer->customer->email); $invoiceAddress = $this->prestaRequest('GET', "addresses/$order->id_address_invoice"); $invoiceAddress = $invoiceAddress->address; @@ -263,6 +263,14 @@ class Shopimporter_Presta extends ShopimporterBase } } + $taxes = []; + $this->app->erp->RunHook('getTaxRatesFromShopOrder', 2, $taxedCountry, $taxes); + + if (isset($taxes['normal']) && $taxes['normal'] > 0) + $cart['steuersatz_normal'] = $taxes['normal']; + if (isset($taxes['ermaessigt']) && $taxes['ermaessigt'] > 0) + $cart['steuersatz_ermaessigt'] = $taxes['ermaessigt']; + $cart['articlelist'] = []; foreach ($order->associations->order_rows->order_row as $order_row) { diff --git a/www/pages/steuersaetze.php b/www/pages/steuersaetze.php index 88830761..7cc77d71 100644 --- a/www/pages/steuersaetze.php +++ b/www/pages/steuersaetze.php @@ -1,4 +1,4 @@ - +*/ +?> app->DB->SelectArr( sprintf( - "SELECT DISTINCT `satz` + "SELECT DISTINCT `type`, `satz` FROM `steuersaetze` WHERE `aktiv` = 1 AND (`country_code` = '%s' OR (`bezeichnung` = '%s' AND `country_code` = ''))", @@ -163,7 +163,7 @@ class Steuersaetze { ); if(!empty($taxes)) { foreach($taxes as $rates) { - $ret[] = $rates['satz']; + $ret[$rates['type']] = $rates['satz']; } } From 0e3afa437be922a1fc9f3a7c02f3fb0fff536ff1 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 29 Jan 2023 12:06:32 +0100 Subject: [PATCH 03/12] Bugfix shopimport, bugfixes presta, support for project specific number ranges --- www/lib/class.erpapi.php | 14 +++++++++++++- www/pages/shopimport.php | 8 ++++---- www/pages/shopimporter_presta.php | 14 +++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index 8f04e543..c12a4d90 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -29440,10 +29440,22 @@ function Firmendaten($field,$projekt="") $process_lock = $this->app->erp->ProzessLock("erpapi_getnextnummer"); $eigenernummernkreis = 0; + $newbelegnr = ''; if($eigenernummernkreis=='1') { + $allowedtypes = ['angebot', 'auftrag', 'rechnung', 'lieferschein', 'arbeitsnachweis', 'reisekosten', + 'bestellung', 'gutschrift', 'kundennummer', 'lieferantennummer', 'mitarbeiternummer', 'waren', + 'produktion', 'sonstiges', 'anfrage', 'artikelnummer', 'kalkulation', 'preisanfrage', 'proformarechnung', + 'retoure', 'verbindlichkeit', 'goodspostingdocument', 'receiptdocument']; - } else { + $dbfield = "next_$type"; + $dbvalue = $this->app->DB->Select("SELECT $dbfield FROM projekt WHERE id='$projekt' LIMIT 1"); + if (!empty($dbvalue)) { + $newbelegnr = $this->CalcNextNummer($dbvalue); + $this->app->DB->Update("UPDATE projekt SET $dbfield='$newbelegnr' WHERE id='$projekt' LIMIT 1"); + } + } + if (empty($newbelegnr)) { // naechste switch($type) { diff --git a/www/pages/shopimport.php b/www/pages/shopimport.php index 397b7a89..291e3d90 100644 --- a/www/pages/shopimport.php +++ b/www/pages/shopimport.php @@ -1,4 +1,4 @@ - +*/ +?> app->erp->KundeAnlegen($typ,$name,$abteilung, // $unterabteilung,$ansprechpartner,$adresszusatz,$strasse,$land,$plz,$ort,$email,$telefon,$telefax,$ustid,$partner,$projekt); - if(strlen($warenkorb['kundennummer'])!=''){ + if(!empty($warenkorb['kundennummer'])){ $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='{$warenkorb['kundennummer']}' $adresseprojekt AND geloescht!=1 LIMIT 1"); } diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 69149240..0a329611 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -253,15 +253,11 @@ class Shopimporter_Presta extends ShopimporterBase if (!empty($cart['lieferadresse_land']) && $this->taxationByDestinationCountry) { $taxedCountry = $cart['lieferadresse_land']; } - if (strval($order->total_paid_tax_incl) === strval($order->total_paid_tax_excl)) { - if ($this->app->erp->IstEU($taxedCountry)) { - $cart['ust_befreit'] = 1; - } elseif ($this->app->erp->Export($taxedCountry)) { - $cart['ust_befreit'] = 2; - } else { - $cart['ust_befreit'] = 3; - } - } + $lieferschwelle = $this->app->DB->Select("SELECT * FROM lieferschwelle WHERE empfaengerland='$taxedCountry' LIMIT 1"); + if ($this->app->erp->IstEU($taxedCountry) || !empty($lieferschwelle['ueberschreitungsdatum'])) { + $cart['ust_befreit'] = 1; + } elseif ($this->app->erp->Export($taxedCountry)) { + $cart['ust_befreit'] = 2; $taxes = []; $this->app->erp->RunHook('getTaxRatesFromShopOrder', 2, $taxedCountry, $taxes); From 1af809954c4a2198f51b943afea596eae914e77f Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 29 Jan 2023 12:08:47 +0100 Subject: [PATCH 04/12] Bugfix shopimport, bugfixes presta, support for project specific number ranges --- www/pages/shopimporter_presta.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 0a329611..4ad949ce 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -258,7 +258,8 @@ class Shopimporter_Presta extends ShopimporterBase $cart['ust_befreit'] = 1; } elseif ($this->app->erp->Export($taxedCountry)) { $cart['ust_befreit'] = 2; - + } + $taxes = []; $this->app->erp->RunHook('getTaxRatesFromShopOrder', 2, $taxedCountry, $taxes); From 100024391db3a5e881a1d1c8f38ba6a49b33715d Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 29 Jan 2023 14:34:47 +0100 Subject: [PATCH 05/12] Bugfixes presta, support for project specific number ranges --- www/lib/class.erpapi.php | 2 +- www/pages/shopimporter_presta.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index c12a4d90..554317a3 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -29439,7 +29439,7 @@ function Firmendaten($field,$projekt="") $process_lock = $this->app->erp->ProzessLock("erpapi_getnextnummer"); - $eigenernummernkreis = 0; + $eigenernummernkreis = $this->app->DB->Select("SELECT eigenernummernkreis FROM projekt WHERE id='$projekt' LIMIT 1"); $newbelegnr = ''; if($eigenernummernkreis=='1') { diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 4ad949ce..f874464c 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -253,13 +253,13 @@ class Shopimporter_Presta extends ShopimporterBase if (!empty($cart['lieferadresse_land']) && $this->taxationByDestinationCountry) { $taxedCountry = $cart['lieferadresse_land']; } - $lieferschwelle = $this->app->DB->Select("SELECT * FROM lieferschwelle WHERE empfaengerland='$taxedCountry' LIMIT 1"); + $lieferschwelle = $this->app->DB->SelectArr("SELECT * FROM lieferschwelle WHERE empfaengerland='$taxedCountry' LIMIT 1"); if ($this->app->erp->IstEU($taxedCountry) || !empty($lieferschwelle['ueberschreitungsdatum'])) { $cart['ust_befreit'] = 1; } elseif ($this->app->erp->Export($taxedCountry)) { $cart['ust_befreit'] = 2; } - + $taxes = []; $this->app->erp->RunHook('getTaxRatesFromShopOrder', 2, $taxedCountry, $taxes); From bcf2544735077ada89900d2f1057c0660e8a69cb Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 29 Jan 2023 14:50:15 +0100 Subject: [PATCH 06/12] Bugfixes presta, support for project specific number ranges --- www/lib/class.erpapi.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index 554317a3..4dcc75d8 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -29440,7 +29440,7 @@ function Firmendaten($field,$projekt="") $process_lock = $this->app->erp->ProzessLock("erpapi_getnextnummer"); $eigenernummernkreis = $this->app->DB->Select("SELECT eigenernummernkreis FROM projekt WHERE id='$projekt' LIMIT 1"); - $newbelegnr = ''; + $belegnr = ''; if($eigenernummernkreis=='1') { $allowedtypes = ['angebot', 'auftrag', 'rechnung', 'lieferschein', 'arbeitsnachweis', 'reisekosten', @@ -29449,13 +29449,13 @@ function Firmendaten($field,$projekt="") 'retoure', 'verbindlichkeit', 'goodspostingdocument', 'receiptdocument']; $dbfield = "next_$type"; - $dbvalue = $this->app->DB->Select("SELECT $dbfield FROM projekt WHERE id='$projekt' LIMIT 1"); - if (!empty($dbvalue)) { + $belegnr = $this->app->DB->Select("SELECT $dbfield FROM projekt WHERE id='$projekt' LIMIT 1"); + if (!empty($belegnr)) { $newbelegnr = $this->CalcNextNummer($dbvalue); $this->app->DB->Update("UPDATE projekt SET $dbfield='$newbelegnr' WHERE id='$projekt' LIMIT 1"); } } - if (empty($newbelegnr)) { + if (empty($belegnr)) { // naechste switch($type) { From 4eac5fbbdc7e20006baf272a6edac8a02f50df79 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 29 Jan 2023 15:38:30 +0100 Subject: [PATCH 07/12] Bugfixes presta, support for project specific number ranges --- www/lib/class.erpapi.php | 2 +- www/pages/shopimporter_presta.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index 4dcc75d8..de87fb3e 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -29451,7 +29451,7 @@ function Firmendaten($field,$projekt="") $dbfield = "next_$type"; $belegnr = $this->app->DB->Select("SELECT $dbfield FROM projekt WHERE id='$projekt' LIMIT 1"); if (!empty($belegnr)) { - $newbelegnr = $this->CalcNextNummer($dbvalue); + $newbelegnr = $this->CalcNextNummer($belegnr); $this->app->DB->Update("UPDATE projekt SET $dbfield='$newbelegnr' WHERE id='$projekt' LIMIT 1"); } } diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index f874464c..68fda8d6 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -278,7 +278,7 @@ class Shopimporter_Presta extends ShopimporterBase 'articleid' => strval($order_row->product_reference), 'name' => strval($order_row->product_name), 'quantity' => strval($order_row->product_quantity), - 'price_netto' => strval($order_row->product_price), + 'price_netto' => strval($order_row->unit_price_tax_excl), 'steuersatz' => $steuersatz ]; } From 406811872c724bd109dc384ce3d15d9f3ed832d3 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Tue, 31 Jan 2023 12:08:25 +0100 Subject: [PATCH 08/12] Prestashop: Tracking and shipping costs w/o tax --- www/pages/shopimporter_presta.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 68fda8d6..1aa7870f 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -162,7 +162,11 @@ class Shopimporter_Presta extends ShopimporterBase $this->prestaRequest('POST', 'order_histories', $obj->asXML()); - //TODO Tracking + $req = $this->prestaRequest('GET', "order_carriers?filter[order_id]=$auftrag&display=[id]"); + $orderCarrierId = strval($req->order_carriers->order_carrier[0]->id); + $req = $this->prestaRequest('GET', "order_carriers/$orderCarrierId"); + $req->order_carrier->tracking_number = $this->data['tracking']; + $this->prestaRequest('PUT', "order_carriers/$orderCarrierId", $req->asXML()); } public function ImportGetAuftraegeAnzahl() @@ -199,7 +203,7 @@ class Shopimporter_Presta extends ShopimporterBase $cart['auftrag'] = strval($order->id); $cart['onlinebestellnummer'] = strval($order->reference); $cart['gesamtsumme'] = strval($order->total_paid); - $cart['versandkostenbrutto'] = strval($order->total_shipping); + $cart['versandkostennetto'] = strval($order->total_shipping_tax_excl); $cart['bestelldatum'] = strval($order->date_add); $carrier = $this->prestaRequest('GET', "carriers/$order->id_carrier"); From 36322b01716709e280a45978851e0103c345f32d Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Tue, 31 Jan 2023 12:19:09 +0100 Subject: [PATCH 09/12] Prestashop: fix typo --- www/pages/shopimporter_presta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 1aa7870f..d8b34b28 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -162,7 +162,7 @@ class Shopimporter_Presta extends ShopimporterBase $this->prestaRequest('POST', 'order_histories', $obj->asXML()); - $req = $this->prestaRequest('GET', "order_carriers?filter[order_id]=$auftrag&display=[id]"); + $req = $this->prestaRequest('GET', "order_carriers?filter[id_order]=$auftrag&display=[id]"); $orderCarrierId = strval($req->order_carriers->order_carrier[0]->id); $req = $this->prestaRequest('GET', "order_carriers/$orderCarrierId"); $req->order_carrier->tracking_number = $this->data['tracking']; From f495964d2b78667b9fa856152eefbd8450472d78 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 5 Feb 2023 22:22:44 +0100 Subject: [PATCH 10/12] Prestashop: add missing strval() calls --- www/pages/shopimporter_presta.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index d8b34b28..60fd40c2 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -195,7 +195,6 @@ class Shopimporter_Presta extends ShopimporterBase $fetchedOrders = []; foreach ($ordersToProcess as $currentOrderId) { - $this->Log("Importing order from presta", [$this->data, $ordersToProcess, $currentOrderId]); $order = $this->prestaRequest('GET', "orders/$currentOrderId"); $order = $order->order; $cart = []; @@ -217,7 +216,7 @@ class Shopimporter_Presta extends ShopimporterBase $invoiceCountry = $this->prestaRequest('GET', "countries/$invoiceAddress->id_country"); $invoiceCountry = $invoiceCountry->country; $cart['name'] = "$invoiceAddress->firstname $invoiceAddress->lastname"; - if (!empty($invoiceAddress->company)) { + if (!empty(strval($invoiceAddress->company))) { $cart['ansprechpartner'] = $cart['name']; $cart['name'] = strval($invoiceAddress->company); } @@ -231,14 +230,14 @@ class Shopimporter_Presta extends ShopimporterBase $cart['ustid'] = strval($invoiceAddress->vat_number); $cart['land'] = strval($invoiceCountry->iso_code); - if ($order->id_address_invoice != $order->id_address_delivery) { + if (strval($order->id_address_invoice) != strval($order->id_address_delivery)) { $deliveryAddress = $this->prestaRequest('GET', "addresses/$order->id_address_delivery"); $deliveryAddress = $deliveryAddress->address; $deliveryCountry = $this->prestaRequest('GET', "countries/$deliveryAddress->id_country"); $deliveryCountry = $deliveryCountry->country; $cart['abweichendelieferadresse'] = 1; $cart['lieferadresse_name'] = "$deliveryAddress->firstname $deliveryAddress->lastname"; - if (!empty($deliveryAddress->company)) { + if (!empty(strval($deliveryAddress->company))) { $cart['lieferadresse_ansprechpartner'] = $cart['lieferadresse_name']; $cart['lieferadresse_name'] = strval($deliveryAddress->company); } From d23c0f09dd668f64f1d960fbf0a30c17b401055d Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Tue, 21 Feb 2023 17:14:56 +0100 Subject: [PATCH 11/12] apply customer language --- www/pages/shopimporter_presta.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 60fd40c2..818c56fc 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -211,6 +211,11 @@ class Shopimporter_Presta extends ShopimporterBase $customer = $this->prestaRequest('GET', "customers/$order->id_customer"); $cart['email'] = strval($customer->customer->email); + $language = $this->prestaRequest('GET', "languages/{$customer->customer->id_lang}"); + if ($language->language->iso_code == "en") { + $cart['kunde_sprache'] = 'englisch'; + } + $invoiceAddress = $this->prestaRequest('GET', "addresses/$order->id_address_invoice"); $invoiceAddress = $invoiceAddress->address; $invoiceCountry = $this->prestaRequest('GET', "countries/$invoiceAddress->id_country"); From cd73a58ecebd41cd0d9daf2de2680df82788aabd Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Tue, 28 Feb 2023 13:40:31 +0100 Subject: [PATCH 12/12] add copyright/license --- www/lib/class.erpapi.php | 7 +++++++ www/lib/class.remote.php | 7 +++++++ www/pages/appstore.php | 7 +++++++ www/pages/shopimport.php | 7 +++++++ www/pages/shopimporter_presta.php | 6 ++++++ www/pages/steuersaetze.php | 7 +++++++ 6 files changed, 41 insertions(+) diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index de87fb3e..a6dfeac7 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -1,4 +1,11 @@