Spree Commerce, eBay Trading API, and the eBay Accelerator Toolkit from Intradesys EbatNs

I thought that I would write this out to help future users, I may turn this into a plugin/extension for Spree at some point, but for now, I will just give you the basic files and ideas. Please note, now and again when I save this file, some weird code errors show up. Please correct an obvious errors without notifying me, because if it’s truly glaring, it’s probably something that happened while editing in WordPress. Like str_replace(“<!–$bt–>”, is obviously wrong, but it keeps doing it, go figure.

I have some custom columns on the Taxons and Products tables;

Your tables don’t have to look like that, and there is nothing to stop you from getting and storing the information
any other way. I was working with a legacy table and database from the clients eBay FileExchange .csv days. The last
table is for some basic reporting, it tracks the errors on the API calls and if there are more than 3 errors, it notifies me
by email and stops sending until it is reset.

Once your tables look like that, you will need to have a directory structure/files in your RAILS_ROOT like so:

We put everything in lib, except ebay_notify.php which is the notification handler. Now let’s create the files:

With the notification handler, for some reason, it simply refused to parse the SOAP request, I couldn’t figure it out, and no xml parsing would work, so instead of bashing my head against the wall, I wrote a dumb file parser. This should work for most needs, or if you want to try and get the notification to parse, be my guest.

Finally, how does it all work:

1. Create a cronjob with crontab -e and add this line:
*/5 * * * * root php /var/www/yourrailsroot/lib/ebay_send.php > /dev/null
This will cause a cronjob to run every 5 minutes, forever, to poll the database.

2. In your spree code, you will need to add something like this:

As for sending items to ebay, you just have to flag them in the database by setting send_to_ebay = 1, however you want to do it is fine.

Or however you are doing it in your latest spree, as I recall, right after I switched to spree, they did what all ROR developers do, and broke everything, restructuring the entire thing. Why? “Because fuck backwards compatibility” is the motto of Rails. (I am using the newest spree on another clients store, and actually it really was an improvement and is easier to use.)

In looking over the code to accomplish all of this, and getting it working smoothly, I feel a bit like an idiot that it took me so damn long to grok it, but there you go.

Naturally, the above is not complete, you’ll need to follow the discussions and tutorials and docs on developer.ebay.com and get your app keys setup. If you need some help, or have a question, post a comment.

About Jason

I am a 31 year old programmer living in the south of France. I currently work actively in the fields of Ruby/PHP/Javascript and server/website administration.
This entry was posted in PHP Tutorials, PHP/MySQL, Tips and Tricks, Web Design and tagged , , , . Bookmark the permalink.