If you are tring to make a google merchant feed for your Zencart store this is the tutorial for you. Copy the script below and upload it to your server. You will have to edit a few things first.
- Database Connection Setting
- Database Prefix
In the script below you can get your database connection setting from the includes > configure.php file. Replace the username, password and database. Next replace all the zen_ with your database prefix. You can see your database prefix in the configure.php file as well. You may need to add other things as well but this script will get you started in the right direction.
<?php $conn=mysqli_connect("localhost","username","password","database"); if (mysqli_connect_errno($conn)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $q = mysqli_query($conn,"SELECT * FROM zen_products_description"); header("Content-type: text/xml"); echo '<?xml version="1.0"?> <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"> <channel> <title>yourwebsite.com</title> <link>http://yourwebsite.com</link> <description>Google Merchant Feed</description>'; while($r = mysqli_fetch_array($q)) { $theid=htmlentities($r['products_id']); $q2 = mysqli_query($conn,"SELECT * FROM zen_products WHERE products_id='$theid' "); while($r2 = mysqli_fetch_array($q2)) { $mcid=htmlentities($r2['master_categories_id']); $qdd4 = mysqli_query($conn,"SELECT categories_name, categories_id FROM zen_categories_description WHERE categories_id='$mcid' "); while($ddr4 = mysqli_fetch_array($qdd4)) { $category=htmlentities($ddr4['categories_name']); } $image=htmlentities('https://yourwebsite.com/images/'); $image.=htmlentities($r2['products_image']); $mid=$r2['manufacturers_id']; $q3 = mysqli_query($conn,"SELECT * FROM zen_manufacturers WHERE manufacturers_id='$mid' "); while($r3 = mysqli_fetch_array($q3)) { $brand=htmlentities($r3['manufacturers_name']); } $gtin=htmlentities($r2['products_model']); $mpn=htmlentities($r2['products_model']); $price=htmlentities($r2['products_price']); if ($r2['products_quantity'] > 0){$availability='in stock';}else{$availability='out of stock';} } $title=htmlentities($r['products_name']); $link=htmlentities('http://yourwebsite.com/index.php?main_page=product_info&cPath=776&products_id='); $link.=htmlentities($r['products_id']); $description=htmlentities($r['products_description']); $id=htmlentities($r['products_id']); $condition='new'; echo "<item> <title>$title</title> <link>$link</link> <description>$description</description> <g:google_product_category>$category</g:google_product_category> <g:id>$id</g:id> <g:condition>$condition</g:condition> <g:price>$price USD</g:price> <g:availability>$availability</g:availability> <g:image_link>$image</g:image_link> <g:gtin>$gtin</g:gtin> <g:brand>$brand</g:brand> <g:mpn>$mpn</g:mpn> <g:product_type>$category</g:product_type> </item>";} ?></channel> </rss>
Please like, share and subscribe.
I hope you enjoyed the article. If I was able to help you please consider a tip for the content.
One Time Tip
Reoccuring Tips
