Merge pull request #89 from exciler/prestashop-improve-import

Prestashop improve import
This commit is contained in:
OpenXE-ERP 2023-07-27 10:56:14 +02:00 committed by GitHub
commit 5557c54fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 15 deletions

View File

@ -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'];
@ -631,8 +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'] = $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'] != '')
{

View File

@ -333,34 +333,64 @@ 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['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);
$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['preis_netto'] = strval($product->product->price);
$res['kurztext_de'] = strip_tags($shortdescriptions['de']);
$res['kurztext_en'] = strip_tags($shortdescriptions['en']);
$res['hersteller'] = strval($product->product->manufacturer_name);
$res['ean'] = strval($product->product->ean13);
$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) {
$endpoint = "images/products/$productid/$img->id";
$endpoint = "images/products/$productId/$img->id";
$imgdata = $this->prestaRequest('GET', $endpoint, '', true);
$images[] = [
'content' => base64_encode($imgdata),