Timeline of a bugfix

2:00pm (yesterday): While reviewing site changes with our designer one day prior to launch, I noticed that the shopping cart functionality was screwed up. Badly. The site is using Commerce for Drupal 7, and when you change options for a product prior to clicking “Add to Cart”, it’s supposed to refresh the form with new details and an updated price. Instead, the form disappears. Obviously, this can’t be launched and fixed later.

2:30pm: Using tried and true developer skills, I basically poke the code with a stick here and there to try and isolate the nature of the problem. Whenever an option is changed — on any product page — the form containing the options and “Add to Cart” button is removed and doesn’t reappear.

3:00pm: Distracting project meeting.

3:30pm: It looks like there’s some AJAX functionality that isn’t working right. JavaScript console contains no errors; stepping through the code reveals no obvious problems. The AJAX functionality seems to be doing exactly what it’s supposed to.

4:00pm: A coworker, clearly unaware of my frustration and panic, persistently asks for a hard timeline for when I’ll have this fixed. I try, and fail, to make him understand that I can’t give him a time estimate until I know what’s wrong first. Management intervenes.

4:30pm: I resign myself to the notion that there’s nothing wrong with the JavaScript, since I clearly remember it working correctly a few days ago. This leads me to think about rolling back the code, except for one thing: some of the code is in the database instead of Git. Fortunately, I’ve been making daily MySQL dumps of the entire CMS database. Restoring the database dump from last week Friday fixes the problem. Unfortunately, I’ll have to add back changes I’ve made to the site one by one. I duplicate the site, import the old database dump to the copy, and start copying changes from the Drupal admin dashboard, checking the shopping cart functionality after each and every save.

5:15pm: Problem located! Adding a view (showing related products) to the bottom of the product page breaks the shopping cart; removing it makes it work as intended. I still don’t know what’s wrong, but at least I know where it’s wrong.

5:30pm: A little testing confirms that this is the entirety of the problem. I hatch a theory as to the nature of the problem — perhaps there’s a duplicated id attribute inside the HTML for the related-products view that’s breaking the JavaScript? I can’t imagine where, but it would explain everything. Meanwhile, my coworkers suggest that at the very least, we can replace the view with static HTML until we isolate the actual bug. I leave to catch my train.

7:30am (this morning): It occurs to me that if the problem is a duplicated id attribute, replacing the view with static HTML won’t fix the problem. I’ll have to test that.

8:30am: I add back the related-products view in the CMS, then remove the HTML containing it by hand. Sure enough, the shopping cart functionality works as intended. So it is something in the HTML, possibly a duplicate ID, and replacing the view with static HTML probably won’t help. Instead, I start at the top level of the view and remove nested elements one level deep at a time to try and isolate where the problem exists.

9:00am: Found it! Thanks to code reuse, the related-products view also contains a form to change options and add to cart, but it’s been hidden using CSS. And since the related-products view also contains the current product (I couldn’t figure out how to remove it earlier), it contains an add-to-cart form with the exact same ID as the one at the top of the page that’s not hidden. A little poking around in the Drupal view interface later, I find exactly where that form is being added to the view block and remove it. Everything appears fixed.

9:15am: Everything still appears fixed, thank goodness. I brag a little to my coworkers and dump the changed database (and upload it off-site) for safekeeping. I reward myself with a few minutes browsing Facebook, then get back to making sure everything is in order for launch.

10:30am: Launch apparently isn’t happening until tomorrow. Figures.

11:00am: I work out how to remove the current product from the related-products view. Figures.

Leave a Reply

Your email address will not be published. Required fields are marked *

*