File: D:/HostingSpaces/SBogers10/deensekroon.komma-mediadesign.nl/wwwroot/php/miinto/MiintoXmlWriter.php
<?php
class MiintoXmlWriter
{
public function write($products)
{
// Create XML file
$xmlString = '<products>';
foreach($products as $product)
{
$xmlString .= '<!-- Product ' . $product->id . ' -->';
$xmlString .= '<product>';
// Basics
$xmlString .= '<id>' . $product->id . '</id>';
$xmlString .= '<title><![CDATA[' . $product->title . ']]></title>';
$xmlString .= '<description><![CDATA[' . $product->description . ']]></description>';
$xmlString .= '<price>' . $product->price . '</price>';
$xmlString .= '<old_price>' . $product->old_price . '</old_price>';
$xmlString .= '<brand><![CDATA[' . $product->brand . ']]></brand>';
$xmlString .= '<category>' . $product->category . '</category>'; // Miinto Id
$xmlString .= '<styleid>' . $product->id . '</styleid>';
if(isset($product->variation))
{
// Variations
$xmlString .= '<variations>';
$xmlString .= '<variation>';
// Variations: Color
$xmlString .= '<color>' . $product->variation->color . '</color>';
// Variations: Sizes
$xmlString .= '<sizes>';
foreach($product->variation->sizes as $size)
{
$xmlString .= '<size>';
$xmlString .= '<title><![CDATA[' . $size->size . ']]></title>';
$xmlString .= '<stock>' . $size->inStock . '</stock>';
$xmlString .= '<gtin>' . trim($size->ean) . '</gtin>';
$xmlString .= '</size>';
}
$xmlString .= '</sizes>';
// Variations: Photos
$xmlString .= '<photos>';
$xmlString .= $this->writePhotos($product);
$xmlString .= '</photos>';
$xmlString .= '</variation>';
$xmlString .= '</variations>';
}
$xmlString .= '</product>';
}
$xmlString .= '</products>';
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo $xmlString;
exit;
}
private function writePhotos($product)
{
$xmlString = '';
if(isset($product->variation->photos))
{
foreach($product->variation->photos as $shortCode => $photo)
{
$xmlString .= '<photo>';
$xmlString .= '<url><![CDATA[' . $photo . ']]></url>'; // Needs to be escaped
$xmlString .= '<is_default>';
$thumb = $shortCode == $product->thumb;
$thumb ? $xmlString .= '1' : $xmlString .= '0';
$xmlString .= '</is_default>';
$xmlString .= '</photo>';
}
}
return $xmlString;
}
}