Post by Digital Sushi » Fri Jan 28, 2011 3:03 pm

I’m looking for a bit of help. Right now I’m writing a PHP file which generates an XML from the product database. This is for anyone from South Africa that wants to use Bid or Buy product feed system; once it’s done you can have it for free. I know that OpenCart has Google Base built in, but the store cannot accept that at all.

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="";

?>
Can anyone help me out?

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.
Last edited by Digital Sushi on Fri Jan 28, 2011 4:01 pm, edited 1 time in total.

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by justinv » Fri Jan 28, 2011 3:51 pm

Hmm.. this is probably not the best way to do what you are trying to do. You are bypassing the OpenCart system and heading straight to the database, when you could be using the OpenCart product database queries and making your life easier.

I suggest you copy/paste the google_base.php files, call them bid_buy.php and modify them to the format you want. Or if you are not using the google_base module, just modify it in catalog/controller/feed/google_base.php to output the attributes that you do want.

Or if you're willing to pay $9 the extension Any Feed in my signature will produce the feed that you are looking for.

Documentation: OpenCart User Guide
Mods: Total Import PRO | CSV Import PRO | Ecom Tracking | Any Feed | Autosuggest | OpenCart CDN
Image


Active Member

Posts

Joined
Tue Oct 12, 2010 1:24 pm

Post by Digital Sushi » Fri Jan 28, 2011 3:59 pm

Try it's not and it's controlled by a Cronjob as well. It's the only way I know how to.

I bought the Any Feed, but it gives me errors: http://digitalsushi.co.za/index.php?route=feed/any_feed

(sorry, I replied to your mail earlier, but I though it was to someone else, so the feed still isn't working for me).

Bid or Buy like xml the way I my example is, from what they say.

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by Digital Sushi » Sat Feb 19, 2011 4:12 am

Okay I've been chatting more and more to Bid or Buy and it must be a .xml file that is submitted. I'm not pretty far in the code, but I'm having some problems. Can anyone help with this?

1. The feed must only display products that I have in stock i.e. 0 <.
2. Categories. I need to display all of the categories in 1 row. i.e. cat 1 - cat 2 - cat 3

Here 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>All Digital Sushi products</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 output: http://digitalsushi.co.za/bidorbuy.xml

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by CasJ » Wed Mar 23, 2011 8:38 pm

Hi there, did you ever find a solution for this, I also need to create this XML for Bid or Buy?
Thanks!

Newbie

Posts

Joined
Wed Nov 24, 2010 10:36 pm
Who is online

Users browsing this forum: No registered users and 3 guests