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.
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.
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
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.