This file contains 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
<script> | |
fetchType: '’Collection’ or ‘Product’', | |
fetchId: 'collection or product ID', | |
</script> |
This file contains 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
client.fetchProduct('your-product-id').then(function(product) { | |
var html = | |
"<img class='product__image' src='" + product.selectedVariantImage.src + "' >" + | |
"<h2 class='product__title'>" + product.title + "</h2>" + | |
"<a class='product__buy' href='" + | |
product.selectedVariant.checkoutUrl(1) + | |
"'>Buy Now!</a>"; | |
$('#product-1').html(html); |
This file contains 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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script src="jquery.sticky.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$(".add-to-cart").sticky({topSpacing:50}); | |
}); | |
</script> |
This file contains 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
.product { | |
max-width: 400px; | |
box-shadow: 0 0 15px 5px #eee; | |
padding: 30px; | |
} | |
.product__buy { | |
background: #7ab55c; | |
padding: 0.5625em 1.875em; | |
color: white; |
This file contains 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
var selectedVariant = product.selectedVariant; | |
var selectedVariantImage = product.selectedVariantImage; | |
var currentOptions = product.options; |
This file contains 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
var variantSelectors = generateSelectors(product); | |
$('.variant-selectors').html(variantSelectors); | |
function generateSelectors(product) { | |
var elements = product.options.map(function(option) { | |
return '<select name="' + option.name + '">' + option.values.map(function(value) { | |
return '<option value="' + value + '">' + value + '</option>'; | |
}) + '</select>'; | |
}); |
This file contains 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
function attachOnVariantSelectListeners(product) { | |
$('.variant-selectors').on('change', 'select', function(event) { | |
var $element = $(event.target); | |
var name = $element.attr('name'); | |
var value = $element.val(); | |
product.options.filter(function(option) { | |
return option.name === name; | |
})[0].selected = value; | |
var selectedVariant = product.selectedVariant; |
This file contains 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
var $cartLineItems = checkout.lineItems.map(function (lineItem, index) { | |
var $lineItemTemplate = $(lineItemEmptyTemplate); | |
var itemImage = lineItemImages[lineItem.variant_id]; | |
$lineItemTemplate.find('.cart-item__img').css('background-image', 'url(' + itemImage + ')'); | |
$lineItemTemplate.find('.cart-item__title').text(lineItem.title); | |
$lineItemTemplate.find('.cart-item__variant-title').text(lineItem.variant_title); | |
$lineItemTemplate.find('.cart-item__price').text(formatAsMoney(lineItem.line_price)); | |
$lineItemTemplate.find('.cart-item__quantity').attr('value', lineItem.quantity); | |
$lineItemTemplate.find('.quantity-decrement').attr('data-variant-id', lineItem.variant_id); | |
$lineItemTemplate.find('.quantity-increment').attr('data-variant-id', lineItem.variant_id); |
This file contains 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
function openCart() { | |
$('.cart').addClass('js-active'); | |
} | |
function closeCart() { | |
$('.cart .btn--close').click(function () { | |
$('.cart').removeClass('js-active'); | |
}); | |
} |