From cb2b75a3ca90f7bf23eb88296726f93482f0820b Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Tue, 25 Jul 2023 00:02:25 +0200 Subject: [PATCH 1/4] Prestashop: Improve article import --- www/lib/class.remote.php | 5 ++++- www/pages/shopimporter_presta.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/www/lib/class.remote.php b/www/lib/class.remote.php index 9dbfd069..ce0cf898 100644 --- a/www/lib/class.remote.php +++ b/www/lib/class.remote.php @@ -559,7 +559,7 @@ class Remote $steuersatz_normal = 19; } $crossellingInstalled = $this->app->erp->ModulVorhanden('crossselling'); - foreach($reta as $k => $ret) + foreach($reta as $k => $ret) { if(isset($ret['stueckliste'])){ $stuecklistenmechanik = $ret['stueckliste']; @@ -633,6 +633,9 @@ class Remote $arr['name_de'] = $ret['name']; $arr['uebersicht_de'] = isset($ret['uebersicht_de'])?$ret['uebersicht_de']:''; $arr['kurztext_de'] = isset($ret['kurztext_de'])?$ret['kurztext_de']:''; + $arr['name_en'] = $ret['name_en']; + $arr['uebersicht_en'] = isset($ret['uebersicht_en'])?$ret['uebersicht_en']:''; + $arr['kurztext_en'] = isset($ret['kurztext_en'])?$ret['kurztext_en']:''; //$arr['anabregs_text'] = isset($ret['uebersicht_de'])?$ret['uebersicht_de']:''; if(isset($ret['ean']) && $ret['ean'] != '') { diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index f02a8114..9bc5be23 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -346,6 +346,7 @@ class Shopimporter_Presta extends ShopimporterBase $product = $this->prestaRequest('GET', "products/$productid"); $res = []; $res['nummer'] = strval($product->product->reference); + $res['shoparticleid'] = intval($productid); $res['artikelnummerausshop'] = strval($product->product->reference); $names = $this->toMultilangArray($product->product->name->language); $descriptions = $this->toMultilangArray($product->product->description->language); @@ -354,6 +355,8 @@ class Shopimporter_Presta extends ShopimporterBase $res['name_en'] = $names['en']; $res['uebersicht_de'] = $descriptions['de']; $res['uebersicht_en'] = $descriptions['en']; + $res['kurztext_de'] = $shortdescriptions['de']; + $res['kurztext_en'] = $shortdescriptions['en']; $res['preis_netto'] = strval($product->product->price); $res['hersteller'] = strval($product->product->manufacturer_name); $res['ean'] = strval($product->product->ean13); From fa4125d63b212811a5ae8b2c2227abffbd92a049 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Wed, 26 Jul 2023 12:38:41 +0200 Subject: [PATCH 2/4] Prestashop: strip html tags from short description --- www/pages/shopimporter_presta.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index 9bc5be23..a698dca4 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -355,8 +355,8 @@ class Shopimporter_Presta extends ShopimporterBase $res['name_en'] = $names['en']; $res['uebersicht_de'] = $descriptions['de']; $res['uebersicht_en'] = $descriptions['en']; - $res['kurztext_de'] = $shortdescriptions['de']; - $res['kurztext_en'] = $shortdescriptions['en']; + $res['kurztext_de'] = strip_tags($shortdescriptions['de']); + $res['kurztext_en'] = strip_tags($shortdescriptions['en']); $res['preis_netto'] = strval($product->product->price); $res['hersteller'] = strval($product->product->manufacturer_name); $res['ean'] = strval($product->product->ean13); From 1a94af6b0b7a061148988e3a3b1a56ea5697bf16 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Wed, 26 Jul 2023 15:26:01 +0200 Subject: [PATCH 3/4] Prestashop: import support combinations --- www/pages/shopimporter_presta.php | 44 ++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index a698dca4..f3885b19 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -333,21 +333,41 @@ class Shopimporter_Presta extends ShopimporterBase if (empty($nummer)) return; - $searchresult = $this->prestaRequest('GET', 'products?filter[reference]='.$nummer); - if (empty($searchresult)) { + $productsresult = $this->prestaRequest('GET', 'products?filter[reference]='.$nummer); + $combinationsresult = $this->prestaRequest('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; } - 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"); + $isCombination = $numberOfCombinations > 0; + if ($isCombination) { + $combinationId = intval($combinationsresult->combinations->combination->attributes()->id); + $combination = $this->prestaRequest('GET', "combinations/$combinationId"); + $productId = intval($combination->combination->id_product); + } else { + $productId = intval($productsresult->products->product->attributes()->id); + } + $product = $this->prestaRequest('GET', "products/$productId"); $res = []; - $res['nummer'] = strval($product->product->reference); - $res['shoparticleid'] = intval($productid); - $res['artikelnummerausshop'] = strval($product->product->reference); + 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); @@ -357,13 +377,11 @@ class Shopimporter_Presta extends ShopimporterBase $res['uebersicht_en'] = $descriptions['en']; $res['kurztext_de'] = strip_tags($shortdescriptions['de']); $res['kurztext_en'] = strip_tags($shortdescriptions['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"; + $endpoint = "images/products/$productId/$img->id"; $imgdata = $this->prestaRequest('GET', $endpoint, '', true); $images[] = [ 'content' => base64_encode($imgdata), From 7df897d9d70c7eb64c5d3252ca240977166b9cdf Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Wed, 26 Jul 2023 18:47:44 +0200 Subject: [PATCH 4/4] Prestashop: import meta infos --- www/lib/class.remote.php | 14 ++++++++++---- www/pages/shopimporter_presta.php | 9 +++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/www/lib/class.remote.php b/www/lib/class.remote.php index ce0cf898..c2f30bbd 100644 --- a/www/lib/class.remote.php +++ b/www/lib/class.remote.php @@ -631,11 +631,17 @@ class Remote } $arr['projekt'] = $shopexportArr['projekt']; $arr['name_de'] = $ret['name']; - $arr['uebersicht_de'] = isset($ret['uebersicht_de'])?$ret['uebersicht_de']:''; - $arr['kurztext_de'] = isset($ret['kurztext_de'])?$ret['kurztext_de']:''; + $arr['uebersicht_de'] = $ret['uebersicht_de'] ?? ''; + $arr['kurztext_de'] = $ret['kurztext_de'] ?? ''; $arr['name_en'] = $ret['name_en']; - $arr['uebersicht_en'] = isset($ret['uebersicht_en'])?$ret['uebersicht_en']:''; - $arr['kurztext_en'] = isset($ret['kurztext_en'])?$ret['kurztext_en']:''; + $arr['uebersicht_en'] = $ret['uebersicht_en'] ?? ''; + $arr['kurztext_en'] = $ret['kurztext_en'] ?? ''; + $arr['metakeywords_de'] = $ret['metakeywords_de'] ?? ''; + $arr['metakeywords_en'] = $ret['metakeywords_en'] ?? ''; + $arr['metatitle_de'] = $ret['metatitle_de'] ?? ''; + $arr['metatitle_en'] = $ret['metatitle_en'] ?? ''; + $arr['metadescription_de'] = $ret['metadescription_de'] ?? ''; + $arr['metadescription_en'] = $ret['metadescription_en'] ?? ''; //$arr['anabregs_text'] = isset($ret['uebersicht_de'])?$ret['uebersicht_de']:''; if(isset($ret['ean']) && $ret['ean'] != '') { diff --git a/www/pages/shopimporter_presta.php b/www/pages/shopimporter_presta.php index f3885b19..cce154a8 100644 --- a/www/pages/shopimporter_presta.php +++ b/www/pages/shopimporter_presta.php @@ -371,6 +371,9 @@ class Shopimporter_Presta extends ShopimporterBase $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']; @@ -378,6 +381,12 @@ class Shopimporter_Presta extends ShopimporterBase $res['kurztext_de'] = strip_tags($shortdescriptions['de']); $res['kurztext_en'] = strip_tags($shortdescriptions['en']); $res['hersteller'] = strval($product->product->manufacturer_name); + $res['metakeywords_de'] = $metakeywords['de']; + $res['metakeywords_en'] = $metakeywords['en']; + $res['metatitle_de'] = $metatitles['de']; + $res['metatitle_en'] = $metatitles['en']; + $res['metadescription_de'] = $metadescriptions['de']; + $res['metadescription_en'] = $metadescriptions['en']; $images = []; foreach ($product->product->associations->images->image as $img) {