I’m almost there, but my PHP coding isn’t that great and I’m still requiring the file to do 3 more things.
The file must skip any inactive product
The file must skip any product whose quantity is 0
Remove any duplicated items (by SKU), because if a product has more than 1 category it duplicates it
This is my code:
Code: Select all
<?php
// connect to database
$db_name = "database";
$connection = mysql_connect("localhost", "user", "password") or die("Could not connect.");
// querying mysql
$db = mysql_select_db($db_name, $connection) or die("Could not connect.");;
$result = mysql_query("SELECT * FROM product_description NATURAL JOIN product");
// XML File Creation
$buf ='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT>
<Products>
';
while($row=mysql_fetch_array($result)) {
// rounds off the price from 4 to 2 decimals
$rowprice = round($row[14], 2);
$buf .= "<Product>
<ProductCode><![CDATA[".htmlentities($row[7]) ."]]></ProductCode>
<Title><![CDATA[". htmlentities($row[2]) ."]]></Title>
<Category><![CDATA[ categories ]]></Category>
<Price>". htmlentities($rowprice) .".00</Price>
<Quantity>". htmlentities($row[9]) ."</Quantity>
<Condition>New</Condition>
<Location>Cape Town</Location>
<ShippingOption>Courier</ShippingOption>
<ImageURL><![CDATA[http://www.digitalsushi.co.za/image/". htmlentities($row[11]) ."]]></ImageURL>
<Description><![CDATA[".html_entity_decode($row[5]) ."]]></Description>
</Product>
";
}
$buf .= "</Products>
</ROOT>";
echo $buf;
// creates a .xml file in the root directory
$file=fopen("bidorbuy.xml","w");
fwrite($file,$buf);
fclose($file);
mysql_close($connection);;
$buf="";
?>
Here is an example of the final product: http://www.digitalsushi.co.za/bidorbuy.xml
I know that OpenCart has Google Base built in, but the store cannot accept that at all.