There are numerous ways to allow your customers to add items to cart. In some instances, it might be sufficient to add a single item to cart. Perhaps you need to allow your customers to add multiple variants? Or maybe you need a really lean and efficient method that doesn't bog down your page loading speeds with unnecessary scripts and bloated JSON data.

CodeShopify outlines a great method and gives you all the Javascript, CSS/HTML, and Liquid bits. Everything is covered from the modal, display method, and logic for the actual ajax call and subsequent success and fail routines.

Even if this isn't exactly what you're after, it's likely that there's some useful techniques to glean. It's especially useful to be reminded of the importance of taking the time craft a thoughtful UI/UX.

Give it a read here.