Fixing the Bug

(Check out Bandcamp’s new embedded players!)

Finally it’s time to fix this shipping bug. So mainly what I’ve got to do is fix the receipts sent to both buyer and seller by modifying the liquid templates. In the buyer receipt I need to add the mailing address and provide a means of contacting the artist if the mailing address needs to be changed. Through a bit of manipulating and playing with stylistic changes, this is what a receipt now looks like (my changes are shown in the 2nd gray box):

Screen Shot 2013-06-10 at 6.45.02 AM

In the seller receipt I need to add the sku (an inventory id for packages that can be turned on by the merchant) and link the band’s name to their home page. This was a little more complicated than just updating the liquid files because I needed to figure out where to find the sku in the database. Turns out it’s stored in three tables: packages, package_options, and sale_items. In theory the sku number should never be different from table to table, but since the band can change the sku at any time, it’s best to fetch it from the sale_items table. The sale_items table takes a snapshot of the package information when a sale is made, this way the information is identical to what the user saw.

The liquid template takes a ruby hash called items with the receipt information, and the hash is filled in from a large query on the database. So in order to get the sku, all I had to do was adjust that query. The query was already selecting from sale_items but the sku is stored as an id, not text, and the id corresponds to an entry in another database table called sale_item_syms, which maps the id to the actual text. This is a clever way of saving storage space in the database by only storing a string once. Therefore, after adding a join in the query with the sku sym_id, the items hash now has the sku text and is available in the receipt template. Check out the linked band name and sku now seen in the seller receipt:

Screen Shot 2013-06-19 at 7.57.37 AM

And that’s it! Internship over. Just kidding.

Advertisements

2 thoughts on “Fixing the Bug

  1. Hi! Reading your blog has been both interesting and enlightening, and I hope you have an awesome time interning at Bandcamp. I know this isn’t exactly the place for feature requests, but I wondered, after reading this and a few other posts of yours, if this wasn’t related since you’re talking about orders, receipts, etc…

    On the customer side of things, when placing an order, people can buy a single (physical) item with, say, a quantity of 2, or they can buy two of that item by going through the buying process twice. On the artist side, we get a ba-da-boom email regardless of which they do, but the same can’t be said for the merch_orders page. If the customer did the first option we see one order of two, and if they did the second option, we see two completely different orders. To boot, if they order two different items, we also see two completely different orders.

    The problem is, even though Bandcamp provides the nice feature for combining shipping on multiple items, it’s easy for the artist to overlook that two orders are going to the same place, accidentally sending out two packages to one individual rather than one package, costing us money.

    I feel bad just posting this as a comment, but it seemed along the lines of what you’ve been working on and thought you might be able to help (or to put it another way, maybe “see if this is something Bandcamp wants you to work on”). =]

    Best wishes again with your internship!

    • Thank you for the comment and well wishes, Inverse Phase! This definitely sounds like a problem we can address. When I mentioned this to the other engineers it seemed like they had already been trying to think of a solution for how to deal with multiple merch orders from the same buyer. Sounds like they’re working on an idea now and depending on how my new project goes I might get to help out with this. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s