Created
January 29, 2015 04:32
-
-
Save gterrill/570bcb23b035c451c987 to your computer and use it in GitHub Desktop.
Booking Deposit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% comment %} | |
Create a linklist called Deposit and link it to your deposit product | |
{% endcomment %} | |
{% assign deposit_linklist = linklists.deposit.links %} | |
{% if deposit_linklist.size > 0 and deposit_linklist.first.type == 'product_link' %} | |
{% assign deposit_id = deposit_linklist.first.object.variants.first.id %} | |
{% assign deposit_count = 0 %} | |
{% assign bta_product_count = 0 %} | |
{% for item in cart.items %} | |
{% if item.id == deposit_id %} | |
{% assign deposit_count = item.quantity %} | |
{% endif %} | |
{% if item.product.metafields.bookthatapp.config %} | |
{% capture bta_product_count %}{{ bta_product_count | plus: item.quantity }}{% endcapture %} | |
{% endif %} | |
{% endfor %} | |
{% assign bta_product_count = bta_product_count | plus:0 %} | |
<style> | |
#updates_{{ deposit_id }} { display: none; } | |
</style> | |
<script> | |
deposit = { | |
updateQuantity: function(qty) { | |
var data = { | |
updates: { | |
{{ deposit_id }}: qty | |
} | |
}; | |
jQuery.ajax({ | |
type: 'POST', | |
url: '/cart/update.js', | |
data: data, | |
dataType: 'json', | |
success: function() { document.location.href = '/cart'; } | |
}); | |
}, | |
} | |
{% if cart.items.size == 1 and deposit_count > 0 %} | |
// no products other than deposit in cart | |
jQuery(function() { | |
deposit.updateQuantity(0); | |
}); | |
{% elsif deposit_count != bta_product_count %} | |
// deposit: {{ deposit_count }} | |
// product: {{ bta_product_count }} | |
jQuery(function() { | |
deposit.updateQuantity({{ bta_product_count }}); | |
}); | |
{% endif %} | |
</script> | |
{% else %} | |
<p style="clear: both;"> | |
<strong>Please <a href="/admin/link_lists/new">create a link list</a> named <em>Deposit</em> containing a link to your deposit product.</strong> | |
</p> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment