Unique Vintage Accessories => Unique Needs

Narwhal Company logo

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.

FoxyCart as an “Ecommerce Framework”

JSON, AJAX, and Product Locking

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.

Narwhal Company printable invoice

XML and Inventory

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.

Technical Functionality Overview

When A User Requests to View Any Page

Before the page is sent the script does the following:

  • Unlocks any product locks that have expired (locks that haven’t been refreshed for over 15 minutes).
  • Renews any valid product locks for this user (items in their shopping cart) for another 15 minutes.

When A User Requests to View A Product Page

Only products that are marked in the database as available and unlocked are diplayed.

When A User Trys to Add an Item to Their Shopping Cart

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.

  • If the item is available for purchase and does not have a lock on it:
    • A product lock is put on the item for this user, which reserves the item for this user for 15 minutes from their last page view on the site.
    • The item is added to their shopping cart.
  • If the item has a lock on it (not yet sold, but in somebody else’s shopping cart):
    • A message telling the user the item has been reserved for a different user is diplayed.
    • The item is not added to their shopping cart.
  • If the item has been purchased by a different user since the page loaded for this user:
    • A message tellilng the user the item has been purchased is diplayed.
    • The item is not added to their shopping cart.

When A User Views Their Cart

Before the cart is diplayed (using the fctbPreProcess () method) a javascript cycles through the FoxyCart JSON object. This is done to:

  • Make a list of all the items that were in the cart when its opened to compare against the items in the cart when its closed to see which (if any) items the user has removed from the cart.
  • Look for products that are one-of-a-kind and disable the quanity field in the shopping cart to ensure the user doesn’t try to buy two of a unique product.

When A User Closes Their Cart

As the cart is being closed (using the fctbBuildFoxyCa

TRUNCATED! Please download pandoc if you want to convert large files.