Skip to content

Instantly share code, notes, and snippets.

@BibleLeagueInternational
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BibleLeagueInternational/f53ed918c6bc82602489 to your computer and use it in GitHub Desktop.
Save BibleLeagueInternational/f53ed918c6bc82602489 to your computer and use it in GitHub Desktop.
GMC datafeed script
<?php
require '/includes/class.common.php';
require '/includes/class.images.php';
// mysql connection
$conn=mysqli_connect("localhost","database","password","database_name");
// Check connection
if (mysqli_connect_errno($conn))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Collect data in query
$q = mysqli_query($conn,"SELECT id,isbn13,title,retail,discount, product_inventory.bli as stock,description FROM products
LEFT JOIN product_extras ON products.id = product_extras.product_id
LEFT JOIN product_inventory ON products.id = product_inventory.product_id
LEFT JOIN product_descriptions ON products.id = product_descriptions.product_id");
// Set the xml header
header("Content-type: text/xml");
// xml file meta
echo '<?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>store.bibleleague.org</title>
<link>http://store.bibleleague.org</link>
<description>Google Merchant Feed</description>';
// while loop, this will cycle through the products and echo out all the variables
while($r = mysqli_fetch_array($q))
{
// collect all variables
$title =$r['title'];
$link = 'https://store.bibleleague.org/item/'.$x['id'].'/'.$this->common->formatString($x['title'],'url-link').’”’; //Unsure how to grab this
$description=$r['description'];
$id =$r['id'];
$price =$r['retail'];
if ($r['stock'] >= 1){$availability='in stock';}else{$availability='out of stock';}
$image ='http://store.bibleleague.org/#'; //Unsure how to grab this
$gtin =$r['isbn13'];
// output all variables into the correct google tags
// gtin is isbn13
// category is a string preset by Google. It looks like 'Media > Books'
// unsure how to grab shipping price
echo "<item>
<title>$title</title>
<link>$link</link>
<description>$description</description>
<g:google_product_category>Media > Books</g:google_product_category>
<g:id>$id</g:id>
<g:condition>new</g:condition>
<g:price>$price USD</g:price>
<g:availability>$availability</g:availability>
<g:image_link>$image</g:image_link>
<g:shipping>
<g:country>US</g:country>
<g:service>Standard</g:service>
<g:price> USD</g:price>
</g:shipping>
<g:gtin>$gtin</g:gtin>
</item>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment