Prestashop: import support combinations

This commit is contained in:
Andreas Palm 2023-07-26 15:26:01 +02:00
parent fa4125d63b
commit 1a94af6b0b

View File

@ -333,21 +333,41 @@ class Shopimporter_Presta extends ShopimporterBase
if (empty($nummer)) if (empty($nummer))
return; return;
$searchresult = $this->prestaRequest('GET', 'products?filter[reference]='.$nummer); $productsresult = $this->prestaRequest('GET', 'products?filter[reference]='.$nummer);
if (empty($searchresult)) { $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); $this->Log('No product found in Shop', $this->data);
return; return;
} }
if (count($searchresult->products->product) > 1) {
$this->Log('Got multiple results from Shop', $this->data);
}
$productid = $searchresult->products->product->attributes()->id; $isCombination = $numberOfCombinations > 0;
$product = $this->prestaRequest('GET', "products/$productid"); 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 = [];
$res['nummer'] = strval($product->product->reference); if ($isCombination) {
$res['shoparticleid'] = intval($productid); $res['nummer'] = strval($combination->combination->reference);
$res['artikelnummerausshop'] = strval($product->product->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); $names = $this->toMultilangArray($product->product->name->language);
$descriptions = $this->toMultilangArray($product->product->description->language); $descriptions = $this->toMultilangArray($product->product->description->language);
$shortdescriptions = $this->toMultilangArray($product->product->description_short->language); $shortdescriptions = $this->toMultilangArray($product->product->description_short->language);
@ -357,13 +377,11 @@ class Shopimporter_Presta extends ShopimporterBase
$res['uebersicht_en'] = $descriptions['en']; $res['uebersicht_en'] = $descriptions['en'];
$res['kurztext_de'] = strip_tags($shortdescriptions['de']); $res['kurztext_de'] = strip_tags($shortdescriptions['de']);
$res['kurztext_en'] = strip_tags($shortdescriptions['en']); $res['kurztext_en'] = strip_tags($shortdescriptions['en']);
$res['preis_netto'] = strval($product->product->price);
$res['hersteller'] = strval($product->product->manufacturer_name); $res['hersteller'] = strval($product->product->manufacturer_name);
$res['ean'] = strval($product->product->ean13);
$images = []; $images = [];
foreach ($product->product->associations->images->image as $img) { 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); $imgdata = $this->prestaRequest('GET', $endpoint, '', true);
$images[] = [ $images[] = [
'content' => base64_encode($imgdata), 'content' => base64_encode($imgdata),