Skip to content

Instantly share code, notes, and snippets.

$(function() {
var client = ShopifyBuy.buildClient({
apiKey: 'your-api-key',
domain: 'your-shop-subdomain.myshopify.com',
appId: '6'
});
});
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);
.product {
max-width: 400px;
box-shadow: 0 0 15px 5px #eee;
padding: 30px;
}
.product__buy {
background: #7ab55c;
padding: 0.5625em 1.875em;
color: white;
var selectedVariant = product.selectedVariant;
var selectedVariantImage = product.selectedVariantImage;
var currentOptions = product.options;
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>';
});
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);
<table> <!--“Desktop” width: 600px - 300*2-->
<tr>
<td class=”col” width=”300”>...</td>
<td class=”col” width=”300”>...</td>
</tr>
</table>
@media only screen and (max-width: 600px) {
table, tr, td {
display: block; /* table-cell -> block */
width: 100%;
}
}
<table> <!--“Desktop” width — 600px - 300*2-->
<tr>
<td class=”sub-col” width=”300”>...</td>
<td class=”main-col” width=”300”>...</td>
</tr>
</table>