(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):
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:
And that’s it! Internship over. Just kidding.