Forked from BibleLeagueInternational/gmc_datafeed.php
Last active
August 29, 2015 14:09
-
-
Save jveldboom/371725a8284933d32457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '../includes/class.common.php'; | |
require '../includes/class.images.php'; | |
$common = new common; | |
$images = new images; | |
// 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,upc,isbn,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)) | |
{ | |
$image = $images->getImage($r['isbn13'],$r['isbn'],$r['upc']); | |
// collect all variables | |
$title = $r['title']; | |
$link = 'https://store.bibleleague.org/item/'.$r['id'].'/'.$common->formatString($r['title'],'url-link'); | |
$description = $r['description']; | |
$id = $r['id']; | |
$price = $r['retail']; | |
$availability = ($r['stock'] > 0 ? 'in stock' : 'out of stock'); | |
$image = $image['lg']; | |
$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