Skip to content

Instantly share code, notes, and snippets.

View gterrill's full-sized avatar

Gavin Terrill gterrill

View GitHub Profile
@gterrill
gterrill / cart.js
Last active August 29, 2015 13:56
Ajax Add to Cart with bta.BookingForm
function addToCart(e){
if (typeof e !== 'undefined') e.preventDefault();
// make sure BTA has loaded
if ($('#add-to-cart').hasClass('bta-load-enable')) {
alert('Please wait while we look up class availability');
return false;
}
var form = $(this).parents('form'),
@gterrill
gterrill / styles.css
Created February 11, 2014 19:05
Inline Datepicker CSS Style
span.ui-icon {color: transparent;} /* hide background text */
#ui-datepicker-div { display: none; margin-bottom:20px}
#booking-start {margin-bottom: 10px}
@gterrill
gterrill / bundled.v2.js
Last active August 29, 2015 13:57
Bundle availability including quantity using $.Deffered
; bundles = [];
{% for variant in product.variants %}{% if variant.metafields.sva.bundled %}
bundles['{{ variant.id }}'] = jQuery.parseJSON('{{ variant.metafields.sva.bundled }}');
{% endif %}{% endfor %}
var process= function(target, results) {
var deferred = $.Deferred();
Shopify.getProduct(target.handle, function(product) {
var multiplier = target.multiplier || 1,
@gterrill
gterrill / booking-helper.v2.js
Last active August 29, 2015 13:57
Select variant according to number of days
var selectVariant = function(form) {
var start = form.getStartDate(),
finish = form.getFinishDate();
if (start && finish) {
var quantity = bta.dayDelta(start, finish), minutes = (quantity * 1440);
$('#quantity').val(quantity);
var index = -1, low = 0,
configs = bta.parseVariantConfigs(form.datepicker('start').attr('data-bta-variant-config'));
@gterrill
gterrill / calendar.template.html
Created April 2, 2014 01:09
Show upcoming events using the Ajax API.
<p style="margin:10px 0">
<label for="bta-product-select">Class</label>
<select id="bta-product-select">
<option value="">All Classes</option>
{% for product in products %}
<option value="{{ product.handle }}">{{ product.title }}</option>
{% endfor %}
</select>
</p>
@gterrill
gterrill / booking-form.snippet.html
Created April 30, 2014 21:18
Group size using booking party (and variant price breaks)
{% comment %}
BookThatApp auto installed snippet. Changes made to this file will be lost if installed again.
{% endcomment %}
{% if product.tags contains 'Booking Party' %}
<label for="booking-party">Number of Participants</label>
<div class="selector-wrapper">
<select id="booking-party" name="properties[booking-party]">
{% for n in (1..30) %}
<option>{{ n }}</option>
@gterrill
gterrill / booking-form.snippet.html
Created May 4, 2014 01:16
Reset button for date range
{% comment %}
BookThatApp auto installed snippet. Changes made to this file will be lost if installed again.
{% endcomment %}
{% if product.metafields.bookthatapp.config %}
{% unless bta_configured %}
<div class="booking-form clearfix">
<div class="selector-wrapper">
{% capture attribute %}booking-start{% endcapture %}
<label for="{{ attribute }}">From:</label>
@gterrill
gterrill / file.js
Last active August 29, 2015 14:01
How to validate the booking form
$('form[action*="/cart/add"]').submit(function(e) {
var btaForm = $(this).data('bta.bookingForm');
if ((typeof(btaForm) != "undefined") && !btaForm.isValid()) {
e.stopImmediatePropagation(); // prevents BTA's default form submit handler which also checks for validity
return false;
}
// regular Ajax submit from here...
}
@gterrill
gterrill / calendar.template.html
Created June 3, 2014 20:42
Calendar with images for classes
<div class="span9">
<h1>Art Class Calendar</h1>
<hr />
<em>Sign up for adult classes by clicking the painting on the calendar you would like to come paint.</em>
<div id="bta-calendar"></div>
</div>
<script src="{{ shop.bookthatapp }}/fullcalendar/fullcalendar.js" type="text/javascript"></script>
<script src="{{ shop.bookthatapp }}/javascripts/xdate.js" type="text/javascript"></script>
@gterrill
gterrill / shipping-calculator.liquid
Last active August 29, 2015 14:13
Updated Shipping Calculator
{% unless settings.shipping_calculator == 'Disabled' %}
<div id="shipping-calculator-container" class="clearfix">
<div id="shipping-calculator" class="fl">
<h3>{{ settings.shipping_calculator_heading }}</h3>
<div>
<p>
<label for="address_country">Country</label>
<select id="address_country" name="address[country]" data-default="{% if shop.customer_accounts_enabled and customer %}{{ customer.default_address.country }}{% elsif settings.shipping_calculator_default_country != '' %}{{ settings.shipping_calculator_default_country }}{% endif %}">{{ country_option_tags }}</select>
</p>
<p id="address_province_container" style="display:none;">