mirakl Zwischenstand

This commit is contained in:
OpenXE 2024-05-14 11:00:56 +02:00
parent 9d547c6e52
commit 55e7934fe4
7 changed files with 221 additions and 160 deletions

View File

@ -1111,7 +1111,7 @@ if (typeof document.hidden !== \"undefined\") { // Opera 12.10 and Firefox 18 an
}
// userd edit ajax call
$poll = true;
// $poll = true;
if($poll) {
$this->addPollJs($module, $action, $id);
}

View File

@ -2775,6 +2775,7 @@ class Remote
}
return '';
}
if($shoptyp === 'intern')
{
if($modulename != '')
@ -2788,15 +2789,16 @@ class Remote
$obj->getKonfig($id, $data);
}
$method = 'Import'.$action;
if(method_exists($obj,$method)) {
try {
$ret = $obj->$method();
}
catch(Exception $e) {
if($isActionAuth) {
return 'Fehler Auth: '.$e->getMessage();
}
return 'Fehler: '.$e->getMessage();
}
return '';
}
if(!empty($this->app->stringcleaner)){
@ -2804,6 +2806,8 @@ class Remote
}
$this->parseReturn($ret, $id, $action);
return $ret;
} else {
return 'Fehler: Funktion nicht implementiert: '.$method;
}
}elseif($isActionAuth)
{

View File

@ -2867,6 +2867,7 @@ class Artikel extends GenArtikel {
}
$pageContents = $this->app->remote->RemoteSendArticleList($shop,$artikel,$extartikelnummer);
$check = strpos($pageContents ,'error:');
$msg = '';
if(!empty($pageContents) && is_array($pageContents)) {

View File

@ -3339,7 +3339,7 @@ INNER JOIN shopexport s ON
}
if($this->app->Secure->GetPOST('pruefen')) {
$className = 'Remote';
$methodName = 'RemoteConnection';
$r = new ReflectionMethod($className, $methodName);

View File

@ -11,7 +11,6 @@ class Shopimporter_Mirakl extends ShopimporterBase
private $app;
private $intern;
private $shopid;
private $data;
private $protocol;
private $apiKey;
private $shopUrl;
@ -20,6 +19,8 @@ class Shopimporter_Mirakl extends ShopimporterBase
private $idbearbeitung;
private $idabgeschlossen;
public $data;
// TODO
private $langidToIso = [3 => 'de', 1 => 'en'];
private $taxationByDestinationCountry;
@ -45,14 +46,14 @@ class Shopimporter_Mirakl extends ShopimporterBase
'typ' => 'checkbox',
'bezeichnung' => '{|Protokollierung im Logfile|}:'
],
'textekuerzen' => [
/* '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|}:',
@ -65,9 +66,9 @@ class Shopimporter_Mirakl extends ShopimporterBase
],
'shopidmirakl' => [
'typ' => 'text',
'bezeichnung' => '{|Shop ID des Shops|}:',
'bezeichnung' => '{|Shop ID des Shops (optional, int64)|}:',
'size' => 40,
],
],/*
'steuergruppen' => [
'typ' => 'text',
'bezeichnung' => '{|Steuergruppenmapping|}:',
@ -107,7 +108,7 @@ class Shopimporter_Mirakl extends ShopimporterBase
'typ' => 'checkbox',
'bezeichnung' => '{|Artikelpreis im Shop anzeigen|}:',
'col' => 2
],
],*/
]
];
}
@ -136,15 +137,44 @@ class Shopimporter_Mirakl extends ShopimporterBase
$this->taxationByDestinationCountry = !empty($this->app->DB->Select($query));
}
private function miraklRequest(string $endpoint, string $postdata = null, bool $raw = false)
{
$ch = curl_init($this->shopUrl.$endpoint);
$headers = array("Authorization: ".$this->apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!empty($postdata)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$headers[] = 'Content-Type: application/json';
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$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);
}
public function ImportAuth() {
$ch = curl_init($this->shopUrl);
curl_setopt($ch, CURLOPT_USERNAME, $this->apiKey);
$ch = curl_init($this->shopUrl."version");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: ".$this->apiKey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($code == 200)
return 'success';
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($code == 200) {
return 'success '.print_r($response,true);
}
return $response;
}
@ -314,109 +344,180 @@ class Shopimporter_Mirakl extends ShopimporterBase
return $fetchedOrders;
}
/*
* Fetches article list from the shop, puts them into table shopexport_getarticles, starts the prozessstarter getarticles which fetches details for each article via ImportGetArticle()
*/
public function ImportGetArticleList()
{
$result = [];
$response = $this->miraklRequest('GET', 'products?display=[reference]');
foreach ($response->products->product as $product) {
$result[] = $product->reference;
$response = $this->miraklRequest('offers', raw: true);
$result_array = json_decode($response);
foreach ($result_array->offers as $offer) {
$result[] = $offer->shop_sku;
}
array_unique($result);
return $result;
}
/*
* Fetches article details from the shop
*/
public function ImportGetArticle()
{
$nummer = $this->data['nummer'];
if (isset($this->data['nummerintern'])) {
$nummer = $this->data['nummerintern'];
}
$nummer = trim($nummer);
throw new Exception("Not implemented");
}
if (empty($nummer))
return;
/*
* Send articles to shop
*/
$productsresult = $this->miraklRequest('GET', 'products?filter[reference]='.$nummer);
$combinationsresult = $this->miraklRequest('GET', 'combinations?filter[reference]='.$nummer);
$numberOfCombinations = count($combinationsresult->combinations->combination);
$numberOfProducts = count($productsresult->products->product);
$numberOfResults = $numberOfProducts + $numberOfCombinations;
if ($numberOfResults > 1) {
$this->Log('Got multiple results from Shop', $this->data);
return;
}
elseif ($numberOfResults < 1) {
$this->Log('No product found in Shop', $this->data);
return;
}
public function ImportSendList()
{
$articleList = $this->CatchRemoteCommand('data');
//print_r($articleList);
/*
Array
(
[0] => Array
(
[artikel] => 1
[artikelid] => 1
[nummer] => 700001
[inaktiv] =>
[name_de] => Schraube M10x20
[name_en] =>
[einheit] =>
[hersteller] =>
[herstellernummer] =>
[ean] =>
[artikelnummer_fremdnummern] =>
[kurztext_de] =>
[kurztext_en] =>
[anabregs_text] =>
[anabregs_text_en] =>
[beschreibung_de] =>
[beschreibung_en] =>
[uebersicht_de] =>
[uebersicht_en] =>
[herkunftsland] => DE
[texteuebertragen] => 1
[metadescription_de] =>
[metadescription_en] =>
[metakeywords_de] =>
[metakeywords_en] =>
[metatitle_de] =>
[metatitle_en] =>
[links_de] =>
[altersfreigabe] =>
[links_en] =>
[startseite_de] =>
[startseite_en] =>
[restmenge] => 0
[startseite] => 0
[standardbild] =>
[herstellerlink] =>
[lieferzeit] =>
[lieferzeitmanuell] =>
[gewicht] =>
[laenge] => 0.00
[breite] => 0.00
[hoehe] => 0.00
[wichtig] => 0
[porto] => 0
[gesperrt] => 0
[sperrgrund] =>
[gueltigbis] => 0000-00-00
[umsatzsteuer] => normal
[ausverkauft] => 0
[variante] => 0
[variante_von_id] => 0
[variantevon] =>
[pseudopreis] => 0.00
[keinrabatterlaubt] => 0
[einkaufspreis] => 0.12000000
[pseudolager] =>
[downloadartikel] => 0
[zolltarifnummer] =>
[typ] => 1_kat
[kategoriename] => Handelsware (100000)
[steuer_art_produkt] => 0
[steuer_art_produkt_download] => 0
[anzahl_bilder] => 0
[anzahl_lager] =>
[lagerkorrekturwert] => -0
[autolagerlampe] => 0
[crosssellingartikel] => Array
(
)
$isCombination = $numberOfCombinations > 0;
if ($isCombination) {
$combinationId = intval($combinationsresult->combinations->combination->attributes()->id);
$combination = $this->miraklRequest('GET', "combinations/$combinationId");
$productId = intval($combination->combination->id_product);
} else {
$productId = intval($productsresult->products->product->attributes()->id);
}
$product = $this->miraklRequest('GET', "products/$productId");
$res = [];
if ($isCombination) {
$res['nummer'] = strval($combination->combination->reference);
$res['artikelnummerausshop'] = strval($combination->combination->reference);
$res['ean'] = strval($combination->combination->ean13);
$res['preis_netto'] = floatval($product->product->price) + floatval($combination->combination->price);
} else {
$res['nummer'] = strval($product->product->reference);
$res['artikelnummerausshop'] = strval($product->product->reference);
$res['ean'] = strval($product->product->ean13);
$res['preis_netto'] = floatval($product->product->price);
}
$names = $this->toMultilangArray($product->product->name->language);
$descriptions = $this->toMultilangArray($product->product->description->language);
$shortdescriptions = $this->toMultilangArray($product->product->description_short->language);
$metadescriptions = $this->toMultilangArray($product->product->meta_description->language);
$metakeywords = $this->toMultilangArray($product->product->meta_keywords->language);
$metatitles = $this->toMultilangArray($product->product->meta_title->language);
$res['name'] = $names['de'];
$res['name_en'] = $names['en'];
$res['uebersicht_de'] = $descriptions['de'];
$res['uebersicht_en'] = $descriptions['en'];
$res['kurztext_de'] = strip_tags($shortdescriptions['de']);
$res['kurztext_en'] = strip_tags($shortdescriptions['en']);
$res['hersteller'] = strval($product->product->manufacturer_name);
$res['metatitle_de'] = $metatitles['de'];
$res['metatitle_en'] = $metatitles['en'];
$res['metadescription_de'] = $metadescriptions['de'];
$res['metadescription_en'] = $metadescriptions['en'];
[waehrung] => EUR
[preis] => 0.16000000
[steuersatz] => 19
[staffelpreise_standard] => Array
(
[0] => Array
(
[ab_menge] => 1.0000
[preis] => 0.16000000
[bruttopreis] => 0.1904
[waehrung] => EUR
)
$tags = $product->product->associations->tags->tag;
$keywords = [];
foreach ($tags as $tag) {
$tagid = intval($tag->id);
$endpoint = "tags/{$tagid}";
$tagdata = $this->miraklRequest('GET', $endpoint);
$tagiso = $this->langidToIso[intval($tagdata->tag->id_lang)];
$tagvalue = strval($tagdata->tag->name);
if (!array_key_exists($tagiso, $keywords))
$keywords[$tagiso] = [];
$keywords[$tagiso][] = $tagvalue;
}
$res['metakeywords_de'] = join(',', $keywords['de'] ?? []);
$res['metakeywords_en'] = join(',', $keywords['en'] ?? []);
)
$images = [];
foreach ($product->product->associations->images->image as $img) {
$endpoint = "images/products/$productId/$img->id";
$imgdata = $this->miraklRequest('GET', $endpoint, '', true);
$images[] = [
'content' => base64_encode($imgdata),
'path' => "$img->id.jpg",
'id' => $img->id
];
}
$res['bilder'] = $images;
return $res;
[staffelpreise] => Array
(
[0] => Array
(
[ab_menge] => 1.0000
[preis] => 0.16000000
[bruttopreis] => 0.1904
[waehrung] => EUR
)
)
[bruttopreis] => 0.1904
[checksum] =>
[variantevorhanden] => 0
)
)
*/
$offers_for_mirakl = array();
foreach ($articleList as $article) {
$offers_for_mirakl[] = array(
'product_id_type' => 'sku', // ?!?!
'price' => $article['preis'],
// 'pricing_unit' => $article['waehrung'],
'product_id' => $article['nummer'],
'shop_sku' => $article['nummer'],
'state_code' => '11', // ?!?!
'update_delete' => 'update' // update or delete
);
}
$data_for_mirakl = array();
$data_for_mirakl['offers'] = $offers_for_mirakl;
$json_for_mirakl = json_encode($data_for_mirakl);
$result = [];
$response = $this->miraklRequest('offers', postdata: $json_for_mirakl, raw: true);
$result_array = json_decode($response);
print_r($result_array); // stdClass Object ( [import_id] => 69751 )
exit();
}
private function toMultilangArray($xmlnode) {
@ -454,30 +555,5 @@ class Shopimporter_Mirakl extends ShopimporterBase
$this->app->erp->Logfile($message, print_r($dump, true));
}
}
private function miraklRequest($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);
}
}

View File

@ -228,11 +228,7 @@ class Verbindlichkeit {
$defaultorder = 1;
$defaultorderdesc = 0;
$offen_menge = "TRIM(IF(
pd.menge > COALESCE(vp.menge,0),
pd.menge - COALESCE(vp.menge,0),
0
))+0";
$offen_menge = "";
$auswahl = array (
'<input type=\"checkbox\" name=\"ids[]\" value=\"',
@ -242,10 +238,8 @@ class Verbindlichkeit {
$werte = array (
'<input type="number" name="werte[]" value="',
['sql' => $offen_menge],
'" min="0"',
' max="',
['sql' => $offen_menge],
'"/>'
);
@ -303,7 +297,7 @@ class Verbindlichkeit {
// END Toggle filters
$sql = "
SELECT SQL_CALC_FOUND_ROWS * FROM (
SELECT * FROM (
SELECT
pa.id pa_id,
".$this->app->erp->ConcatSQL($auswahl)." AS auswahl,
@ -316,11 +310,7 @@ class Verbindlichkeit {
art.name_de,
pd.bemerkung,
pd.menge,
IF(
pd.menge > COALESCE(vp.menge,0),
pd.menge - COALESCE(vp.menge,0),
0
) offen_menge,
0 offen_menge,
".$this->app->erp->ConcatSQL($werte).",
".$this->app->erp->ConcatSQL($preise)." AS preis,
if(art.umsatzsteuer = '',art.steuersatz,art.umsatzsteuer) steuer,
@ -329,38 +319,28 @@ class Verbindlichkeit {
CONCAT(skadr.sachkonto,' ',skadr.beschriftung)
) AS sachkonto
FROM
paketannahme pa
INNER JOIN paketdistribution pd ON
paketdistribution pd
LEFT JOIN paketannahme pa ON
pd.paketannahme = pa.id
INNER JOIN artikel art ON
LEFT JOIN artikel art ON
art.id = pd.artikel
LEFT JOIN adresse adr ON
adr.id = pa.adresse
LEFT JOIN bestellung_position bp ON
bp.id = pd.bestellung_position
LEFT JOIN bestellung b ON
b.id = bp.bestellung
LEFT JOIN(
SELECT
paketdistribution,
SUM(menge) AS menge
FROM
verbindlichkeit_position vp
GROUP BY
paketdistribution
) vp
ON
vp.paketdistribution = pd.id
b.id = bp.bestellung
LEFT JOIN
kontorahmen skart ON skart.id = art.kontorahmen
LEFT JOIN
kontorahmen skadr ON skadr.id = adr.kontorahmen
WHERE pa.adresse = ".$lieferant." AND pd.vorlaeufig IS NULL".$innerwhere."
WHERE pa.adresse = '".$lieferant."'
GROUP BY pd.id
) temp
";
$count = "";
// $groupby = "";
$groupby = "";
break;
case 'verbindlichkeit_positionen':

View File

@ -98,7 +98,7 @@
<div class="inside inside-full-height">
<fieldset><legend>{|Aktion|}</legend>
<table width="100%">
<tr><td><input type="button" onclick="verpruefen();" value="{|Verbindung pr&uuml;fen|}" class="aktionbutton" ></td></tr>
<tr><td><input type="submit" form="frmpruefen" value="{|Verbindung pr&uuml;fen|}" class="aktionbutton" ></td></tr>
<tr><td width="50%"><input type="button" onclick="Holeauftrag();" value="{|Auftr&auml;ge abholen|}" class="aktionbutton" ></td></tr>
[AKTIONBUTTONS]
</table>