Most of this was written by steeeeephen, the developer of Narwhal Company’s website. We have a huge crush on him. Read his description of the site’s requirements and his solutions, which might give you some ideas of the power of FoxyCart’s JSON and XML.
Narwhal Co sells mostly one-of-a-kind hand-made accessories made from recycled vintage ties. Because of this, a flexible purchasing system had to be implemented. The system also had to be very transparent, as the look and feel of the site were a high priority. All the shopping cart systems I had tried were either overly cumbersome to setup and work with, or created nightmarish HTML that required hours of tedious trimming and debugging to produce decent looking pages (and code for that matter). Even the stores that bragged about being standards-compliant generate some pretty scary HTML. After weeks of searching for an e-commerce solution that would fit our requirements, we stumbled across FoxyCart. I took the 2-minute tour and that was all it took to realize I had finally found the right system.
Because most of the products in the Narwhal Co. store are one-of-a-kind, it was important to ensure that two people didn’t purchase the same one item. Through use of some AJAX requests, items that are added to a user’s cart they are locked in the database so nobody else can purchase the item for a certain time period: 15 minutes from the user’s last activity on the site.
The inventory system works off of the built-in FoxyCart datafeed. Every time the datafeed is sent, a script goes through the datafeed and makes a list of all the items purchased in the transaction(s). It then automatically changes these products status in the database from available to sold. The other neat feature of the inventory system relates to order fulfillment. Using information pulled from the datafeed a transaction record is created. From this transaction record, the store manager can create a printable invoice to ship with the product, and check which transactions have been shipped and which still need to be.
Before the page is sent the script does the following:
Only products that are marked in the database as available and unlocked are diplayed.
An AJAX (non-asynchronous) request is sent to query the database to get the current status (available, sold, or locked) of the item. This check is important as the item may have been purchased or added to somebody else’s cart since the page initially loaded for this user.
Before the cart is diplayed (using the fc_tb_PreProcess() method) a javascript cycles through the FoxyCart JSON object. This is done to:
As the cart is being closed (using the fc_tb_BuildFoxyCart() method) a javascript cycles through the FoxyCart JSON object again. It compares the list of items in the cart when it was opened against when it was closed to see if there were any items removed from the cart. If there have been items removed from the cart an AJAX (asynchronous this time is okay) request is sent to unlock all the items that has been removed from the cart.
The datafeed is used to accomplish two main tasks: update sold items status in the database and create transaction records. The transaction records also double as an order fulfillment system and are used to track which orders have shipped and to create printable invoinces to accompany the orders.
Love it? Hate it? Have questions or comments? Let us know!