Thank you for your responses.
Below, I've included the relevant code from our PIM application that generates the XML file with the product data and sends it via a web service to our PrestaShop 8.1.6 setup.
I use the web service provided by PrestaShop and have enabled all fields for ease since we are still in the concept phase.
Function to Create the XML File with Product Data
function createProductsXML($productData, array $shopCategories): bool|string
{
$xml = new SimpleXMLElement('<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"></prestashop>');
$product = $xml->addChild('product');
$product->addChild('id_manufacturer', '1');
$product->addChild('id_supplier', '1');
$product->addChild('id_brand', '10');
$product->addChild('id_category_default', array_search($productData->category, $shopCategories));
$product->addChild('new', '1');
$product->addChild('id_default_combination', '1');
$product->addChild('id_tax_rules_group', '1');
$product->addChild('type', '1');
$product->addChild('id_shop_default', '1');
$product->addChild('reference', htmlspecialchars($productData->sku));
$product->addChild('supplier_reference', htmlspecialchars($productData->mpn));
$product->addChild('ean13', htmlspecialchars($productData->ean));
$product->addChild('available_for_order', "1");
$product->addChild('state', '1');
$product->addChild('product_type', 'standard');
$product->addChild('price', number_format($productData->price, 2));
$product->addChild('active', $productData->active ? '1' : '0');
$metaDescription = $product->addChild('meta_description');
$metaDescription->addChild('language', 'Description')->addAttribute('id', '1');
$metaDescription->addChild('language', 'Description')->addAttribute('id', '2');
$metaKeywords = $product->addChild('meta_keywords');
$metaKeywords->addChild('language', '')->addAttribute('id', '1');
$metaKeywords->addChild('language', '')->addAttribute('id', '2');
$metaTitle = $product->addChild('meta_title');
$metaTitle->addChild('language', '')->addAttribute('id', '1');
$metaTitle->addChild('language', '')->addAttribute('id', '2');
$linkRewrite = $product->addChild('link_rewrite');
$linkRewrite->addChild('language', '')->addAttribute('id', '1');
$linkRewrite->addChild('language', '')->addAttribute('id', '2');
$name = $product->addChild('name');
$name->addChild('language', htmlspecialchars($productData->name))->addAttribute('id', '1');
$name->addChild('language', htmlspecialchars($productData->name))->addAttribute('id', '2');
$description = $product->addChild('description');
$description->addChild('language', htmlspecialchars($productData->description))->addAttribute('id', '1');
$description->addChild('language', htmlspecialchars($productData->description))->addAttribute('id', '2');
$descriptionShort = $product->addChild('description_short');
$descriptionShort->addChild('language', '')->addAttribute('id', '1');
$descriptionShort->addChild('language', '')->addAttribute('id', '2');
$associations = $product->addChild('associations');
$categories = $associations->addChild('categories');
$category = $categories->addChild('category');
$category->addChild('id', array_search($productData->category, $shopCategories));
return $xml->asXML();
}
Function to Send the POST Request
public function post(string $url, string $content = null, bool $json_response = false): bool|string
{
if ($json_response) {
$url = $url.'?output_format=JSON';
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if ($content !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/xml',
'Content-Length: ' . strlen($content)
]);
}
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Request Error:' . curl_error($ch));
}
curl_close($ch);
return $response;
}