$url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Accept: application/json',
'X-Auth-Token: ' . $access_token
]
]);
$response = curl_exec($curl);
if ($response === false) {
die('Error: Curl error - ' . curl_error($curl));
}
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($http_status >= 400) {
die('Error: HTTP status - ' . $http_status);
}
curl_close($curl);
$json_response = json_decode($response, true);
if ($json_response === null) {
die('Error: Invalid JSON response');
}
return $json_response;
}
// Function to generate sitemap XML
function generateSitemap() {
$xml = new SimpleXMLElement('');
$products = makeRequest('catalog/products');
if (!empty($products)) {
foreach ($products as $product) {
$url = $xml->addChild('url');
$url->addChild('loc', 'https://www.semipreciousking.com/products/' . $product['id']);
// Add other optional elements like lastmod, changefreq, priority
}
}
$categories = makeRequest('catalog/categories');
if (!empty($categories)) {
foreach ($categories as $category) {
$url = $xml->addChild('url');
$url->addChild('loc', 'https://www.semipreciousking.com/categories/' . $category['id']);
// Add other optional elements
}
}
$pages = makeRequest('pages');
if (!empty($pages)) {
foreach ($pages as $page) {
$url = $xml->addChild('url');
$url->addChild('loc', 'https://www.semipreciousking.com/' . $page['url']);
// Add other optional elements
}
}
// Output sitemap XML
header('Content-Type: application/xml');
echo $xml->asXML();
}
// Generate sitemap
generateSitemap();
?>