Skip to content

Instantly share code, notes, and snippets.

View gterrill's full-sized avatar

Gavin Terrill gterrill

View GitHub Profile
@gterrill
gterrill / booking-form.liquid
Created January 13, 2017 18:11
Restrict availability when variant option being used for number of attendees
<script>
$('form[action="/cart/add"]').on('bta.datetimeChange', function(event, form) {
// restrict number of attendees dropdown to only allow available number of seats
var qtySelector = $('.single-option-selector:first'),
max = form.getAvailability(),
currentQty = parseInt(qtySelector.val(), 10);
qtySelector.find('option').removeAttr('disabled');
qtySelector.find('option').filter(function () {
return parseInt(this.value, 10) > max;
@gterrill
gterrill / bundled.liquid
Last active December 2, 2016 00:06
Debut theme (Slate) changes to support bundle availability check
// theme.liquid
<script>
window.addEventListener("load", function(event) {
$('.single-option-selector').trigger('change'); // trigger bundle check on initial variant
});
</script>
// theme.js - line 2438
_updateAddToCart: function(evt) {
var variant = evt.variant;
@gterrill
gterrill / booking-form.liquid
Last active April 28, 2018 00:18
Restrict options when variants represent quantity
// When a date/time is chosen, update the variant option that represents the number
// of people attending the event.
$('form[action="/cart/add"]').on('bta.datetimeChange', function(event, form) {
var index = form.getAvailability() - 1,
quantitySelector = $('select[data-option="option1"]', $(this)); // assumes the variant option quantity selector is option1
// clear any existing disabled options
quantitySelector.find('option').removeAttr('disabled');
// disabled options > available
@gterrill
gterrill / booking-form.snippet.html
Last active September 28, 2016 04:31
Capture finish date as a read-only or hidden field
{% comment %}
BookThatApp auto installed snippet. Changes made to this file will be lost if installed again.
{% endcomment %}
{% if product.metafields.bookthatapp.config %}
<div class="booking-form">
{% capture attribute %}booking-start{% endcapture %}
<label for="{{ attribute }}-{{ product.handle }}">Start date</label>
<input id="{{ attribute }}-{{ product.handle }}" type="text" name="properties[Date]" size="12"
class="datepicker bta required bta-load-enable bta-dp-start" disabled="disabled"
@gterrill
gterrill / booking-deposit.liquid
Last active July 4, 2020 12:01
Add a booking deposit product to the cart
{% comment %}
Adds deposit products to the cart based on how many
booking products are in the cart.
Instructions:
1. Create a snippet called 'booking-deposit' and paste the contents of this gist. Also create a new Deposit product (must be visible in Online channel)
2. Include the snippet in cart.liquid (at the bottom):
{% include 'booking-deposit' %}
@gterrill
gterrill / cart.liquid
Last active April 16, 2018 06:03
Unriveted: cart.liquid replacement that uses regular liquid instead of rivets (kagami theme)
<div class="row">
<div id="col-main" class="col-sm-12 page-cart">
<h1 class="page-heading">Shopping Cart Summary</h1>
<div class="text-center cart-empty-wrapper" rv-show="cart.item_count | lt 1">
<p class="cart empty">{{ 'cart.general.empty' | t }}</p>
<a href="/collections/all"><i class="fa fa-long-arrow-right"></i> {{ 'cart.general.continue_shopping' | t }}</a>
</div>
@gterrill
gterrill / booking-form-rental-period.liquid
Last active June 3, 2020 08:13
Booking Form allowing units, and updating qty with number of units * days
{% if product.metafields.bookthatapp.config %}
<div class="booking-form">
<div>
{% capture attribute %}booking-start{% endcapture %}
<label for="{{ attribute }}-{{ product.handle }}">From:</label>
<input id="{{ attribute }}-{{ product.handle }}" type="text" name="properties[From]" size="12" class="datepicker bta required bta-load-enable bta-dp-start" disabled="disabled"
data-handle="{{ product.handle }}" data-variant="{{ product.selected_or_first_available_variant.id }}"
data-bta-product-config="{{ product.metafields.bookthatapp.config }}"
data-bta-variant-config="{% for variant in product.variants %}{{ variant.id }}:{{ variant.metafields.bookthatapp.config }}{% unless forloop.last %},{% endunless %}{% endfor %}"
data-bta-range-partner-id="#booking-finish-{{ product.handle }}"
@gterrill
gterrill / bundled.v4.js.liquid
Last active December 9, 2016 09:43
Javascript for showing bundled products as sold out if any component products are sold out
<script>
/*
Script to limit quantity for bundled products.
Instructions: http://support.shopifyconcierge.com/entries/20754371-Synchronizing-Product-Bundle-Inventory
*/
bundles = [];
{% for variant in product.variants %}{% if variant.metafields.sva.bundled %}
bundles['{{ variant.id }}'] = jQuery.parseJSON('{{ variant.metafields.sva.bundled }}');
{% endif %}{% endfor %}
@gterrill
gterrill / booking-deposit.liquid
Last active July 26, 2016 14:08
Add a deposit product to the cart based on cart total
<script>
{% assign deposit = all_products['deposit'] %}
BookingDeposit = function() {
var _this = this;
_this.cart = {{ cart | json }};
_this.depositProduct = {{ deposit | json }};
_this.depositAmount = 0;
_this.depositLine = -1;
_this.cartDepositVariantId = -1;
@gterrill
gterrill / GIF-Screencast-OSX.md
Last active November 27, 2015 01:22 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application: