Hi,
you can parse a comma string into multiple tags. As a result, you will get a format compatible with Google Merchant Center. π
Here is my solution for <g:additional_image_link>
<?php
$xml = simplexml_load_file('https://my-store.com/endpoint/google-merchant-center-products-only', null, LIBXML_NOCDATA);
$rss = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"><channel></channel></rss>');
$rss->channel->addChild('title', 'Google Merchant Feed');
$rss->channel->addChild('link', 'https://my-store.com');
$rss->channel->addChild('description', 'GMC-only-products');
foreach ($xml->entry as $entry) {
$item = $rss->channel->addChild('item');
$gChildren = $entry->children('http://base.google.com/ns/1.0');
$mainImage = (string)$gChildren->image_link;
foreach ($gChildren as $child) {
$name = $child->getName();
if ($name === 'additional_image_link') {
$urls = explode(',', (string)$child);
$count = 0;
foreach ($urls as $url) {
$url = trim($url);
// Skip same main image
if (!empty($url) && $url !== $mainImage) {
$item->addChild("g:additional_image_link", $url, 'http://base.google.com/ns/1.0');
$count++;
}
if ($count >= 10) break;
}
} else {
$item->addChild("g:$name", (string)$child, 'http://base.google.com/ns/1.0');
}
}
}
Header('Content-type: text/xml');
echo $rss->asXML();
Save as my-feed-converter.php and add new file to GMC.
GMC will start processing additional product images after a few minutes. π