Shopify Store - Variant Not adding To Cart - variables

I cannot get my swatch variants to change what product is being added to the cart. No matter what I add it is adding the 'emerson' product. Here is my product.liquid code. I am also using the swatches app.
{% include 'bold-product' with product, hide_action: 'break' %}{% if bold_hidden_product %}{% break %}{%endif %}
<!-- Bold D&H //product -->
{% if product.metafields.inventory.ShappifyHidden == "true" %}
Product is not available
{% break %}{% endif %}
<!-- // end product D&H -->
{% include 'shappify-bdl-no-select' %}
<!-- Bold: Discount D&H -->
{% if product.metafields.inventory.ShappifyHidden == "true" %}
Product is not available
{% else %}
<div id="col-main" class="span12 bva">
<div itemscope itemtype="http://schema.org/Product" class="product-scope">
<meta itemprop="url" content="{{ shop.url }}{{ product.url }}" />
<meta itemprop="name" content="{{ product.title }}" />
<!-- NEW -->
<div class="gallery span8">
<span class=”desc”> {{ product.metafields.lifestyle.gallery }} </span>
</div>
<div class="product-top bva span9">
<div id="product-image" class="product-image bva">
<div id="product" class="row-fluid clearfix">
<div id="product-image" class="span12 product-image">
<div class="product-image-wrapper bva">
<div class="product-thumb-slides">
{% for variant in product.variants %}
{% include 'bold-hidden-variants' with variant, bold_loop: 'loop' %}
{% assign image_variant_available = true %}
{% assign image = variant.image %}
{% assign index = forloop.index | minus: 1 %}
<div data-swatch="{{ image.alt | downcase | handleize }}" data-swatch-color="{{ image.alt }}" data-index="{{ index }}" data-variant-id="{{ variant.id }}">
<img src="{{ image | img_url: 'compact' }}" alt="{% if image.alt contains 'youtube' %}{{ product.title }}{% else %}{{ image.alt | escape }}{% endif %}" />
</div>
{% endfor %}
</div>
<div id="product-image" class="span12 product-image">
<div class="product-image-wrapper">
<a target="_blank" href="{{ product.featured_image | product_img_url: 'original' }}" class="main-image{% if settings.main_image_display == 'zoom' or settings.main_image_display == 'both' %} elevatezoom{% endif %}{% if settings.main_image_display == 'lightbox' %} fancybox{% endif %}">
<img itemprop="image"id="main-image" class="img-zoom img-responsive image-fly" src="{% if shappify_bdl_options_count > 1 %}{{ product.featured_image | product_img_url: 'grande' }}{% else %}{{ product.featured_image | product_img_url: 'original' }}{% endif %}" alt="{{ product.title | escape }}" />
<span class="main-image-bg"></span>
</a>
{% if product.images.size > 1 %}
{% if settings.viewmore_image_display == 'carousel' %}
<div class="gallery_main_wrapper">
{% endif %}
<div id="gallery_main" class="product-image-thumb {% if settings.viewmore_image_display == 'scroll' %}scroll scroll-mini{% endif %} clearfix">
{% for image in product.images %}
{% assign image_variant_available = false %}
{% if image.variants.size > 0 %}
{% for variant in image.variants %}
{% if variant.available %}
{% assign image_variant_available = true %}
{% endif %}
{% endfor %}
{% else %}
{% assign image_variant_available = true %}
{% endif %}
{% if image_variant_available %}
{% if image.alt contains '-alt' %}
{% else %}
<a class="image-thumb{% if forloop.index == 1 %} active{% endif %}" href="{{ image | product_img_url: 'original' }}" data-image-zoom="{{ image | product_img_url: 'original' }}" data-image="{{ image | product_img_url: 'original' }}"onclick="if($('.selector-wrapper .single-option-selector[data-option=\'option1\'] option[value=\'{{ image.alt | replace: "'", "\\'" }}\']').length > 0 && $('.selector-wrapper .single-option-selector[data-option=\'option1\']').val() != '{{ image.alt | replace: "'", "\\'" }}') $('.selector-wrapper .single-option-selector[data-option=\'option1\']').val('{{ image.alt | replace: "'", "\\'" }}'), $('.selector-wrapper .single-option-selector[data-option=\'option1\']').trigger('change');">
<img src="{{ image | product_img_url: 'small' }}" alt="{% if image.alt contains 'youtube' %}{{ product.title }}{% else %}{{ image.alt | escape }}{% endif %}" />
</a>
{% endif %}
{% endif %}
{% endfor %}
{% for image in product.images %}
{% if image.alt contains 'youtube' %}
{% assign embed_url = image.alt %}
<div class="image-thumb-video play-icon">
<img src="{{ image | product_img_url: 'small' }}" alt="{{ product.title | escape }}" />
<a class="play-container fancy" href="{{ embed_url }}" title="{{ product.title }}">
{{ 'play-icon.svg' | asset_url | img_tag: 'Play Video', 'play-image' }}
</a>
<p>WATCH<br>VIDEO</p>
</div>
{% endif %}
{% endfor %}
</div>
{% if settings.viewmore_image_display == 'carousel' %}
</div>
{% endif %}
{% endif %}
</div>
{% if settings.tweet_code == 'below' %}
{% if settings.tweet_code_page != empty %}
<a id="tweet_code" class="btn btn-2" href="{{pages[settings.tweet_code_page].url}}"><i class="icon-hand-right"></i> {{settings.tweet_code_discount_button}}</a>
{% endif %}
{% endif %}
</div>
<script>
jQuery(document).ready(function($){
$('.product-thumb-slides').slick({
slidesToShow: 4,
slidesToScroll: 1,
asNavFor: '.product-slick-gallery',
dots: false,
arrows: true,
focusOnSelect: true,
vertical: true,
centerMode: false,
infintie: false,
nextArrow: '<i class="fa fa-chevron-down slick-next"></i>',
prevArrow: '<i class="fa fa-chevron-up slick-prev"></i>',
});
$('.product-slick-gallery').slick({
arrows: false,
dots : false,
asNavFor: '.product-thumb-slides'
});
$('.quantity').spinner({
min: 1,
change: function(event,ui){
$(this).attr("value", this.value);
//$('.add-cart').attr('data-quantity', this.value);
}
});
$('.product-thumb-slides').on('beforeChange', function(event, slick, currentSlide, nextSlide){
var variantID = $('.product-thumb-slides .slick-slide[data-index="'+nextSlide+'"]').data('variant-id');
var swatch_color = $('.product-thumb-slides .slick-slide[data-index="'+nextSlide+'"]').data('swatch-color');
// console.log(variantID);
//$('.add-cart').attr('data-variant-id', variantID);
$('.hidden-variant-field').attr('value', variantID);
$('.color-name-dynaimc').html(swatch_color);
var $swatch = $('.swatch-element[data-variant-id="'+variantID+'"]');
// console.log($swatch);
if($swatch.hasClass('soldout')){
$('.add-cart').addClass('out-of-stock');
$('.cart-button').html('SOLD OUT');
}else{
$('.add-cart').removeClass('out-of-stock');
$('.cart-button').html('ADD TO CART');
}
});
var productDesc = $('.product-info .product-description p:nth-child(2)').html();
$('.product-info .product-description p:nth-child(2)').html('<strong>DESCRIPTION</strong>'+productDesc);
$('.color-name-dynaimc').html( $('.product-thumb-slides .slick-slide[data-index="0"]').data('swatch-color') );
//$('.add-cart').attr('data-variant-id', $('.product-thumb-slides .slick-slide[data-index="0"]').data('variant-id') );
$('.hidden-variant-field').attr('value', $('.product-thumb-slides .slick-slide[data-index="0"]').data('variant-id') );
// $('.add-cart').click(function(event){
// event.preventDefault();
// var variantID = $(this).data('variant-id');
// var quantity = $(this).data('quantity');
// CartJS.addItem( variantID, quantity);
// setTimeout(function(){
// location.reload();
// },500);
// });
});
</script>
</div>
</div>
</div>
<div class="product-share">
SHARE THIS PRODUCT:
<img src="{{ 'facebook-logo-01.png' | asset_url }}" class="fa fa-facebook social-sharing-icon" style="max-width: 30px" data-network="facebook">
<img src="{{ 'twitter-logo-silhouette-01.png' | asset_url }}" class="fa fa-twitter social-sharing-icon" style="max-width: 30px" data-network="twitter">
<img src="{{ 'pinterest-logo-button-01.png' | asset_url }}" class="fa fa-pinterest social-sharing-icon" style="max-width: 30px" data-network="pinterest">
</div>
</div>
<div class="product-details bva">
<div class="titles">
<div itemprop="name" class="product-name">
<h1>{{ product.title }} <span class="mobile-only">- <span class="color-name-dynaimc"></span></span></h1>
</div>
<div class="detail-price" itemprop="price">
<span class="price">{{ product.price | money }}</span>
</div>
</div>
<div class="variants-wrapper clearfix{% if hide_default_title %} hide{% endif %}">
<select id="product-select-{{ product.id }}" name="id">
{% for variant in product.variants %}
{% include 'bold-hidden-variants' with variant, bold_loop: 'loop' %}
{% if variant.metafields.shappify_bundle.is_bundle == "true" %}{% else %}
<option value="{{ variant.id }}">{{ variant.title | escape }} - {{ variant.price | money }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<form action="/cart/add" method="post" class="product-actions variants " enctype="multipart/form-data">
<div id="product-actions-{{ product.id }}" class="options qty-cart">
<!--<input id="quantity" type="number" name="quantity" value="1" min="1" class="span4 item-quantity" />-->
<div class="input-box">
<input id="quantity" type="text" name="quantity" class="quantity item-quantity" value="1" min="1" />
</div>
<div class="action-wrapper product add-cart">
<div class="product-wait"></div>
<input type="hidden" name="id" value="{{ variant.id }}" class="hidden-variant-field"/>
<button class="cart-button {% if variant.inventory_quantity < 0 %}out-of-stock{% endif %}" unbxdattr="AddToCart" unbxdparam_sku="{{product.id}}" data-parent=".product-information" type="submit" name="add">ADD TO CART</button>
</div>
</div>
</form>
{% unless bundle_loaded == 'true' %}
{% include 'shappify-bdl-load-bundle' %}
{% assign bundle_loaded = 'true' %}
{% endunless %}
<div class="rumepoints">
<strong>You Will Earn:</strong> <span class=”desc”> {{ product.metafields.totes.rumepoints }} </span> <u>RuMe Rewards Points</u> for this item
</div>
</div>
</div>
</div>
</div>
<div class="descriptionusesfeatures">
<div class="product-description">
<strong>DESCRIPTION</strong><br><br>
{{ product.description }}
</div>
<div class="description-right">
<div class="usesforhtml"><strong>USES FOR:</strong><br><br>
<span class=”desc”> {{ product.metafields.usesfor.usesforhtml }} </span>
</div>
<br>
<div class="productfeatures"><strong>FEATURES:</strong><br><br>
<span class=”desc”> {{ product.metafields.features.productfeatures }} </span>
</div>
</div>
</div>
<!-- END -->
{% if settings.product_description_show == 'below' %}
<div itemprop="description" class="description text-left">
<h1>{{ product.title }}</h1>
<!-- {{ product.description }} Replaced with shortcodes version,below -->
{% include 'shortcodes' with product.description %}
</div>
{% endif %}
{% if settings.reviews_enable %}
<div id="shopify-product-reviews" data-id="{{product.id}}">{{ product.metafields.spr.reviews }}</div>
{% endif %}
</div>
{% include 'related-products' %}
<!-- yotpo -->
<div class="yotpo yotpo-main-widget"
data-product-id="{{ product.id }}"
data-name="{{ product.title | escape }}"
data-url="{{ shop.url }}{{ product.url }}"
data-image-url="{{ product.featured_image | product_img_url: "large" |replace: '?', '%3F' | replace: '&','%26'}}"
data-description="{{ product.description | escape }}">
</div>
<!-- yotpo -->
</div>
<!-- end slider wrapper -—>
<!-- Bold: Discount D&H -->
{% endif %}
<script type="text/javascript">
(function e(){var e=document.createElement("script");e.type="text/javascript",e.async=true,e.src="//staticw2.yotpo.com/V3G5rrxyCEg9hXApffAzbDMC6CsghmTdUpbf8D2z/widget.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
</script>
<script type="text/javascript">
$("a.fancy").click(function() {
$.fancybox({
'padding' : 40,
'autoScale' : false,
'transitionIn' : 'fade',
'transitionOut' : 'fade',
'title' : this.title,
'width' : 1280,
'height' : 720,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '?autoplay=1',
'type' : 'swf', // <--add a comma here
'swf' : {'allowfullscreen':'true'} // <-- flashvars here
});
return false;
});
</script>
<script>
// To change what your customers would see if they try to
// add to cart without completing an option, edit the yellow text enclosed within the quotation marks.
var errorMessages = {
for_text_inputs : "Please add your personalized text before adding to cart.",
for_number_inputs: "Please enter a custom quantity.",
for_checkboxes : "Please select your options before adding to cart",
for_dropdowns : "Please select an option before adding to cart"
};
jQuery("form[action='/cart/add'] [type=submit]").on("click", function(e) {
if (
window.Shoppad &&
window.Shoppad.apps &&
window.Shoppad.apps.customizery &&
window.Shoppad.apps.customizery.overrideDeprecatedValidation
) return true;
$io = $('#infiniteoptions-container');
var invalidTextInputs = $io.find("input[type=text][required], textarea").filter(function (idx, el) {
return $(el).val() === '';
});
var invalidNumberInputs = $io.find('input[type=number][required]').filter(function (idx, el) {
return $(el).val() === '';
});
var invalidFieldSets = $io.find('fieldset[data-required=true]').filter(function (idx, fieldSet) {
if ($(fieldSet).find('input[type=checkbox]').length === 0) {
return false;
} else {
return $(fieldSet).find('input[type=checkbox]').filter(function (idx, el) {
return el.checked === true;
}).length === 0;
}
});
var invalidDropdowns = $io.find('select[required]').filter(function (idx, select) {
return !select.selectedOptions[0] || select.selectedOptions[0].disabled === true;
});
var onFail = function (messageType) {
e.stopImmediatePropagation();
alert( errorMessages[messageType] );
return false;
};
if (invalidTextInputs.length > 0) {
return onFail( 'for_text_inputs' );
} else if (invalidNumberInputs.length > 0) {
return onFail( 'for_number_inputs' );
} else if (invalidFieldSets.length > 0) {
return onFail( 'for_checkboxes' );
} else if (invalidDropdowns.length > 0) {
return onFail( 'for_dropdowns' );
} else {
return true;
}
});
</script>
{% include 'shappify-bdl-load-bundle' %}
<script type="text/javascript">
// initialize multi selector for product
jQuery(document).ready(function($){
/* selectCallback */
var selectOptionsCallback = function(variant, selector) {
var add_to_cart = '#add-to-cart';
var $price = '#purchase-' + selector.product.id.toString() + ' .detail-price';
if (variant && variant.available) {
// selected a valid variant
$(add_to_cart).removeClass('disabled').removeAttr('disabled'); // remove unavailable class from add-to-cart button, and re-enable button
if(variant.compare_at_price == null){
$($price).html('<span class="price">'+Shopify.formatMoney(variant.price, "{{shop.money_format}}")+'</span>');
{% if settings.show_multiple_currencies %}
/* Update currency */
currenciesCallbackSpecial('#product-information span.money');
{% endif %}
} else {
$($price).html('<del class="price_compare">' + Shopify.formatMoney(variant.compare_at_price, "{{shop.money_format}}") + '</del>' + '<span class="price_sale">'+Shopify.formatMoney(variant.price, "{{shop.money_format}}") + '</span>');
{% if settings.show_multiple_currencies %}
/* Update currency */
currenciesCallbackSpecial('#product-information span.money');
{% endif %}
}
} else {
$(add_to_cart).addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "Sold Out" : "Unavailable";
$($price).html('<span class="unavailable">' + message + '</span>');
}
if (variant && variant.inventory_quantity && variant.inventory_management == 'shopify') {
jQuery("#stock").html(variant.inventory_quantity).parent().show();
}
else{
jQuery("#stock").parent().hide();
}
{% if settings.trans_product_sku %}
if (variant && variant.sku) {
jQuery("#sku").html(variant.sku).parent().show();
}
else{
jQuery("#sku").parent().hide();
}
{% endif %}
{% if settings.product_barcode_show %}
if (variant && variant.barcode) {
jQuery("#barcode").html(variant.barcode).parent().show();
}
else{
jQuery("#barcode").parent().hide();
}
{% endif %}
//Swapping images JS
$('.product-image-thumb img[alt="'+ $('.selector-wrapper .single-option-selector[data-option=\'option1\']').val() +'"]').first().parent().trigger('click');
};
new Shopify.OptionSelectors("product-select-{{ product.id }}", { product: {{ product | json | remove:'\u003E' | remove:'\u003C' | remove:'\u00a0' }}, onVariantSelected: selectOptionsCallback });
<!-- START Hide OOS Product Varients -->
{% if product.options.size == 1 %}
{% for variant in product.variants %}
{% include 'bold-hidden-variants' with variant, bold_loop: 'loop' %}
{% if variant.metafields.shappify_bundle.is_bundle == "true" %}{% else %}
{% unless variant.available %}
jQuery('.single-option-selector option').filter(function() { return jQuery(this).html() === {{ variant.title | json }}; }).remove();
{% endunless %}
{% endif %}
{% endfor %}
//jQuery('.single-option-selector').trigger('change');
{% endif %}
<!-- END Hide OOS Product Varients -->
// Add label if only one product option and it isn't 'Title'.
{% if product.options.size == 1 and product.options.first != 'Title' %}
$('#product-actions-{{ product.id }} .selector-wrapper:eq(0)').prepend('<label>{{ product.options.first }}</label>');
{% endif %}
// Auto-select first available variant on page load.
{% assign found_one_in_stock = false %}
{% for variant in product.variants %}
{% include 'bold-hidden-variants' with variant, bold_loop: 'loop' %}
{% if variant.metafields.shappify_bundle.is_bundle == "true" %}{% else %}
{% if variant.available and found_one_in_stock == false %}
{% assign found_one_in_stock = true %}
{% for option in product.options %}
$('.single-option-selector:eq({{ forloop.index0 }})').val({{ variant.options[forloop.index0] | json }}).trigger('change');
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
});
</script>
{% include 'windsor-product-tracking' %}Ò

This ended up being a javascript not being able to fire issue. We moved the script higher in the file and corrected the issue.

Related

Broken HTML has been detected in theme's sections/main-cart-footer.liquid

I have an error message in my Shopify store on the cart page. HTML error found Broken HTML has been detected in your theme's sections/main-cart-footer.liquid(opens a new window)file. Check that there are no missing or extra HTML tags present. See code below, can anyone help me address the errors and how to fix them.
{{ 'component-cart.css' | asset_url | stylesheet_tag }}
{{ 'component-totals.css' | asset_url | stylesheet_tag }}
{{ 'component-price.css' | asset_url | stylesheet_tag }}
{{ 'component-discounts.css' | asset_url | stylesheet_tag }}
<div class="page-width{% if cart == empty %} is-empty{% endif %}" id="main-cart-footer" data-id="{{ section.id }}">
<div>
<div class="cart__footer">
{%- if section.settings.show_cart_note -%}
<cart-note class="cart__note field">
<label for="Cart-note">{{ 'sections.cart.note' | t }}</label>
<textarea class="text-area text-area--resize-vertical field__input" name="note" form="cart" id="Cart-note" placeholder="{{ 'sections.cart.note' | t }}">{{ cart.note }}</textarea>
</cart-note>
{%- endif -%}
<div class="cart__blocks">
{% for block in section.blocks %}
{%- case block.type -%}
{%- when '#app' -%}
{% render block %}
{%- when 'subtotal' -%}
<div class="js-contents" {{ block.shopify_attributes }}>
<div class="totals">
<div>
<h3 class="totals__subtotal">{{ 'sections.cart.subtotal' | t }}</h3>
<p class="totals__subtotal-value"><span class="csapps-cart-original-total">{{ cart.total_price | money_with_currency }}</span></p>
</div>
<div data-tbnadhide='NO_DISCOUNT' style='display:none;'>
<h3 class="totals__subtotal">Discount</h3>
<p class="totals__subtotal-value"><span class="csapps-cart-original-total">-<span data-tbnadfield='CART_DISCOUNT'></span></span></p>
</div>
<div data-tbnadhide='NO_DISCOUNT' style='display:none;'>
<h3 class="totals__subtotal">Total</h3>
<p class="totals__subtotal-value"><span class="csapps-cart-original-total"><span data-tbnadfield='CART_TOTAL' class='ymq_cart_total_price'></span></span></p>
</div>
<div>
{%- if cart.cart_level_discount_applications.size > 0 -%}
<ul class="discounts list-unstyled" role="list" aria-label="{{ 'customer.order.discount' | t }}">
{%- for discount in cart.cart_level_discount_applications -%}
<li class="discounts__discount discounts__discount--end">
{%- render 'icon-discount' -%}
{{ discount.title }}
(-{{ discount.total_allocated_amount | money }})
</li>
{%- endfor -%}
</ul>
{%- endif -%}
</div>
<small class="tax-note caption-large rte">
{%- if cart.taxes_included and shop.shipping_policy.body != blank -%}
{{ 'sections.cart.taxes_included_and_shipping_policy_html' | t: link: shop.shipping_policy.url }}
{%- elsif cart.taxes_included -%}
{{ 'sections.cart.taxes_included_but_shipping_at_checkout' | t }}
{%- elsif shop.shipping_policy.body != blank -%}
{{ 'sections.cart.taxes_and_shipping_policy_at_checkout_html' | t: link: shop.shipping_policy.url }}
{%- else -%}
{{ 'sections.cart.taxes_and_shipping_at_checkout' | t }}
{%- endif -%}
</small>
</div>
{%- else -%}
<div class="cart__ctas" {{ block.shopify_attributes }}>
<noscript>
<button type="submit" class="cart__update-button button button--secondary" form="cart">
{{ 'sections.cart.update' | t }}
</button>
</noscript>
<button type="submit" id="checkout" class="cart__checkout-button button" name="checkout"{% if cart == empty %} disabled{% endif %} form="cart">
{{ 'sections.cart.checkout' | t }}
</button>
</div>
{%- if additional_checkout_buttons -%}
<div class="cart__dynamic-checkout-buttons additional-checkout-buttons">
{{ content_for_additional_checkout_buttons }}
</div>
{%- endif -%}
{%- endcase -%}
{% endfor %}
<div id="cart-errors"></div>
</div>
</div>
</div>
</div>
{% javascript %}
class CartNote extends HTMLElement {
constructor() {
super();
this.addEventListener('change', debounce((event) => {
const body = JSON.stringify({ note: event.target.value });
fetch(`${routes.cart_update_url}`, {...fetchConfig(), ...{ body }});
}, 300))
}
}
customElements.define('cart-note', CartNote);
{% endjavascript %}
<script>
document.addEventListener('DOMContentLoaded', function() {
function isIE() {
const ua = window.navigator.userAgent;
const msie = ua.indexOf('MSIE ');
const trident = ua.indexOf('Trident/');
return (msie > 0 || trident > 0);
}
if (!isIE()) return;
const cartSubmitInput = document.createElement('input');
cartSubmitInput.setAttribute('name', 'checkout');
cartSubmitInput.setAttribute('type', 'hidden');
document.querySelector('#cart').appendChild(cartSubmitInput);
document.querySelector('#checkout').addEventListener('click', function(event) {
document.querySelector('#cart').submit();
});
});
</script>
{% schema %}
{
"name": "t:sections.main-cart-footer.name",
"class": "cart__footer-wrapper",
"settings": [
{
"type": "checkbox",
"id": "show_cart_note",
"default": false,
"label": "t:sections.main-cart-footer.settings.show_cart_note.label"
}
],
"blocks": [
{
"type": "subtotal",
"name": "t:sections.main-cart-footer.blocks.subtotal.name",
"limit": 1
},
{
"type": "buttons",
"name": "t:sections.main-cart-footer.blocks.buttons.name",
"limit": 1
},
{
"type": "#app"
}
]
}
{% endschema %}
{% comment %}<!-- ymq option done -->{% endcomment %}
<script id="docapp-shipping-speedup" defer="defer">
(() => { if (!document.documentElement.innerHTML.includes('\\/shop' + '\\/js' + '\\/cart-shipping-calculator-pro.min.js') || window.cartShippingCalculatorProAppLoaded) return; let script = document.createElement('script'); script.src = "https://d1an1e2qw504lz.cloudfront.net/shop/js/cart-shipping-calculator-pro.min.js?shop=texaslonestartamales.myshopify.com"; document.getElementById('docapp-shipping-speedup').after(script); })();
</script>
<script id="docapp-shipping-speedup">
(() => { if (!document.documentElement.innerHTML.includes('\\/shop' + '\\/js' + '\\/cart-shipping-calculator-pro.min.js') || window.cartShippingCalculatorProAppLoaded) return; let script = document.createElement('script'); script.src = "https://d1an1e2qw504lz.cloudfront.net/shop/js/cart-shipping-calculator-pro.min.js?shop=texaslonestartamales.myshopify.com"; document.getElementById('docapp-shipping-speedup').after(script); })();
</script>

Multi file uploader in Shopify Debut theme

I'm customizing my page to upload multiple files (photos). This is the code that I have so far and according to this link it should work:
https://shopify.dev/tutorials/customize-theme-get-customization-information-for-products
in the link go to "Allow file uploads" if you want to check.
{% form 'product', product, class:form_classes, data-product-form: '', enctype:"multipart/form-data" %}
{% unless product.has_only_default_variant %}
<div class="product-form__controls-group">
{% for option in product.options_with_values %}
<div class="selector-wrapper js product-form__item">
<select class="single-option-selector single-option-selector-{{ section.id }} product-form__input"
id="SingleOptionSelector-{{ forloop.index0 }}"
data-index="option{{ forloop.index }}"
>
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
{% endunless %}
<select name="id" id="ProductSelect-{{ section.id }}" class="product-form__variants no-js">
{% for variant in product.variants %}
<option value="{{ variant.id }}"
{%- if variant == current_variant %} selected="selected" {%- endif -%}
>
{{ variant.title }} {%- if variant.available == false %} - {{ 'products.product.sold_out' | t }}{% endif %}
</option>
{% endfor %}
</select>
{% if section.settings.show_quantity_selector %}
{% comment %}
<div class="product-form__controls-group">
<div class="product-form__item">
<input type="number" id="Quantity-{{ section.id }}"
name="quantity" value="1" min="1" pattern="[0-9]*"
class="product-form__input product-form__input--quantity" data-quantity-input
>
</div>
</div>
<div class="qtydiv">
{% comment %}<label for="Quantity" class="quantity-selector">Quantity</label>{% endcomment %}
<div class="qtybox">
<span class="btnqty qtyminus icon icon-minus">-</span>
<input type="text" id="quantity" name="quantity" value="1" min="1" class="quantity-selector quantity-input" readonly="">
<span class="btnqty qtyplus icon icon-plus">+</span>
</div>
</div>
{% endcomment %}
{% endif %}
<div class="product-form__error-message-wrapper product-form__error-message-wrapper--hidden{% if section.settings.enable_payment_button %} product-form__error-message-wrapper--has-payment-button{% endif %}"
data-error-message-wrapper
role="alert"
>
<span class="visually-hidden">{{ 'general.accessibility.error' | t }} </span>
{% include 'icon-error' %}
<span class="product-form__error-message" data-error-message>{{ 'products.product.quantity_minimum_message' | t }}</span>
</div>
<div class="product-form__controls-group product-form__controls-group--submit">
<div class="qtydiv">
{% comment %}<label for="Quantity" class="quantity-selector">Quantity</label>{% endcomment %}
<div class="qtybox">
<span class="btnqty qtyminus icon icon-minus">-</span>
<input type="text" id="quantity" name="quantity" value="1" min="1" class="quantity-selector quantity-input" readonly="">
<span class="btnqty qtyplus icon icon-plus">+</span>
</div>
</div>
<div class="product-form__item product-form__item--submit
{%- if section.settings.enable_payment_button %} product-form__item--payment-button {%- endif -%}
{%- if product.has_only_default_variant %} product-form__item--no-variants {%- endif -%}"
>
<button type="submit" name="add"
{% unless current_variant.available %} aria-disabled="true"{% endunless %}
aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}"
class="btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"
data-add-to-cart>
<span data-add-to-cart-text>
{% unless current_variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
</span>
<span class="hide" data-loader>
{% include 'icon-spinner' %}
</span>
</button>
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
</div>
<input required class="required product-form__input" id="photo" type="file" name="properties[Photo]" multiple>
</div>
</div>
{% endform %}
This is my form that according to the link must have the attribute
enctype = "multipart / form-data".
At the bottom of the form it is in input type = "file".
<input required class="required product-form__input" id="photo" type="file" name="properties[Photo]" multiple>
And this is the code in the cart-template.liquid.
<div class="list-view-item__title">
<a href="{{ item.url }}" class="cart__product-title" data-cart-item-title>
{{ item.product.title }}<br>
{% assign property_size = item.properties | size %}
{% if property_size > 0 %}
{% for p in item.properties %}
{{ item.properties.count }}
{% assign first_character_in_key = p.first | truncate: 1, '' %}
{% unless p.last == blank or first_character_in_key == '_' %}
{{ p.first }}:
{% if p.last contains '/uploads/' %}
<a class="lightbox" href="{{ p.last }}">{{ property_size }}</a>
{% else %}
{{ p.last }}
{% endif %}
<br>
{% endunless %}
{% endfor %}
{% endif %}
</a>
</div>
The problem is the property_size variable gets value one even if I upload two or more images, when in fact I should return the amount of properties that the item has.
Can anyone help me please? What I am doing wrong?
The Debut theme probably has changed since this tutorial was uploaded, and since it is not supported, probably won't be updated.
If you add a type="text" input instead of a type="file" the property gets added as expected. This happens because the _initAddToCart function (assets/theme.js line 6447) gets the form HTML element and pass it along to another function.
var $data = $(this.selectors.productForm, this.$container);
this._addItemToCart($data);
Then in the _addItemToCart function (assets/theme.js line 6513), the form is serialized to a string:
var params = {
url: '/cart/add.js',
data: $(data).serialize(),
dataType: 'json',
};
$.post(params).done(...
This function will ignore the file inputs, as explained in the jQuery documentation:
Data from file select elements is not serialized.
To send the file, the FormData browser API can be used. But to use it with the jQuery AJAX call, some properties must be set:
var params = {
url: '/cart/add.js',
// data: $(data).serialize(),
dataType: 'json',
// Disable the jQuery data processing, and send the FormData object
contentType: false,
processData: false,
data: new FormData($(data).get()[0])
};
$.post(params).done(...
However, since the HTML file <input> has name="properties[Photo]", only the last of the uploaded files will be added to the cart item's Photo property.
I tried with name="properties[Photo][]", but the cart/add.js call only returns an error 500 with the message "Internal Server Error".
So to upload multiple files you could add some custom code to the _addItemToCart function, to get each File from the <input> and add to the FormData with a different key for each file.

Shopify liquid template: repeat HTML code only once

I could successfully add a second hard coded store address in my Shopify template. Now, I'm attempting to add a second address.
The challenge I'm facing is this hard coded address is getting repeated because of a for loop which binds the value from the settings.json file.
The hard coded address is getting repeated three times, since it is being considered by the for loop. But the for loop cannot be removed, because it binds the first address, contact, and visiting hours.
I've tried using an if block with with my hard code, but it didn't work out.
Here is my code:
<div class="container main content main-wrapper">
{% if section.settings.image == nil %}
<h1 class="center">{{ page.title }}</h1>
<div class="feature_divider"></div>
{% endif %}
<div class="sixteen columns featured_links">
<div class="section clearfix feature">
{% for block in section.blocks %}
<div class="{% if section.settings.featured_promos_per_row == 2 %}eight columns {% cycle 'alpha', 'omega' %}{% elsif section.settings.featured_promos_per_row == 3 %}one-third column {% cycle 'alpha', '', 'omega' %}{% else %}four columns {% cycle 'alpha', '', '', 'omega' %}{% endif %} {% if section.settings.featured_links_style != blank %}{{ section.settings.featured_links_style }} {% cycle 'delay-025s', 'delay-05s', 'delay-075s', 'delay-1s' %}{% endif %} center">
{% if block.settings.link != blank %}
<a href="{{ block.settings.link }}">
{% endif %}
<div class="{% if section.settings.rounded_image != blank %}rounded{% endif %}">
{% if block.settings.image != nil %}
<img src="{{ block.settings.image | img_url: '300x' }}"
alt="{{ block.settings.image.alt }}"
data-src="{{ block.settings.image | img_url: '2048x' }}"
class="lazyload"
{% comment %} data-sizes="auto" {% endcomment %}
data-srcset=" {{ block.settings.image | img_url: '2048x' }} 2048w,
{{ block.settings.image | img_url: '1600x' }} 1600w,
{{ block.settings.image | img_url: '1200x' }} 1200w,
{{ block.settings.image | img_url: '1000x' }} 1000w,
{{ block.settings.image | img_url: '800x' }} 800w,
{{ block.settings.image | img_url: '600x' }} 600w,
{{ block.settings.image | img_url: '400x' }} 400w"
/>
{% else %}
{% capture i %}{% cycle "1", "2", "3", "4", "5", "6" %}{% endcapture %}
{{ 'collection-' | append: i | placeholder_svg_tag: 'placeholder-svg placeholder-svg--promotions' }}
{% endif %}
</div>
{% if block.settings.title != blank %}
<h3>{{ block.settings.title | escape }}</h3>
{% if section.settings.show_divider %}
<div class="feature_divider"></div>
{% endif %}
{% endif %}
{% if block.settings.link != blank %}
</a>
{% endif %}
{% if block.settings.text != blank %}
{{ block.settings.text }}
{% endif %}
{% if section.blocks===1%}
<div class="store-new">
<br><p>XYZ</p><p>XYZ,<br>XYZ<br>XYZ</p>
</div>
{% endif %}
</div>
{% if section.settings.featured_promos_per_row == 2 %}
{% cycle '', '<br class="clear " />' %}
{% elsif section.settings.featured_promos_per_row == 3 %}
{% cycle '', '', '<br class="clear" />' %}
{% else %}
{% cycle '', '', '', '<br class="clear" />' %}
{% endif %}
{% endfor %}
</div>
{% if section.settings.contact_address != blank %}
<br class="clear" />
<div class="embed-container maps">
<iframe width="100%" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q={{ section.settings.contact_address | replace: ' ', '+' }}&z={{ section.settings.zoom_level }}&output=embed"></iframe>
</div>
{% endif %}
</div>
</div>
Can someone please help me understand why is this happening?
you can use
{{ if forloop.index0 == 1 }}
or
{{ if forloop.index == 2 }}
instead of
{% if section.blocks===1%}

how to show related produts by tag - shopify

I have a "Related Products" section on my Product page, based with 'Vatage' theme. Now it shows products that a related by "collection". Is it possible to show related products that have the same Tag?
i tried with other codes, but i failed..
please somebody help me.
This is my related-products.liquid code.
Thanks.
{% capture number_of_related_products_to_fetch %}{{ number_of_related_products_to_show | plus: 1 }}{% endcapture %}
{% if collection == null or collection.handle == 'frontpage' or collection.handle == 'all' %}
{% assign found_a_collection = false %}
{% for c in product.collections %}
{% if found_a_collection == false and c.handle != 'frontpage' and c.handle != 'all' and c.all_products_count > 1 %}
{% assign found_a_collection = true %}
{% assign collection = c %}
{% endif %}
{% endfor %}
{% endif %}
<div class="desktop-12 mobile-3">
<h4 class="section-title">{{ 'products.product.related_products' | t }}</h4>
<div id="product-loop">
{% assign current_product_found = false %}
{% for prod in collection.products limit: 7 %}
{% if prod.title == product.title %}
{% assign current_product_found = true %}
{% else %}
{% unless current_product_found == false and forloop.last %}
<div class="product-index desktop-2 tablet-2 mobile-half" id="prod-{{ product.id }}" data-alpha="{{ prod.title }}" data-price="{{ prod.price }}">
<a href="{{ prod.url | within: collection }}" title="{{ prod.title | escape }}">
<img src="{{ prod.featured_image | product_img_url: 'large' }}" alt="{{ product.title | escape }}" />
</a>
<div class="product-info">
<div class="product-info-inner">
<a href="{{ prod.url | within: collection }}">
<h3>{{ prod.title }}</h3>
</a>
<div class="price">
{% if product.price < prod.compare_at_price %}
<div class="onsale">{{ prod.price | money }}</div>
<div class="was">{{ prod.compare_at_price | money }}</div>
{% else %}
<div class="prod-price">{% if prod.price_varies %} {{ 'products.general.from' | t }} {{ prod.price_min | money }} - {{ prod.price_max | money }} {% else %}{{ prod.price | money }}{% endif %}</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endunless %}
{% endif %}
{% endfor %}
</div>
</div>
<!-- Solution brought to you by Caroline Schnapp -->
<!-- See this: http://wiki.shopify.com/Related_Products -->
{% assign image_size = 'compact' %}
{% assign heading = 'Other fine products' %}
{% if product.tags.size > 0 %}
<h3>{{ heading }}</h3>
<ul class="related-products"></ul>
<style type="text/css">
.related-products { list-style-type:none }
{% case image_size %}
{% when 'small' %}
.related-products * { font-size:12px; text-align:center; padding:0 }
.related-products h4 { border:none; margin:10px 0 0 0; line-height:1.3 }
.related-products div.image { height:100px }
.related-products li { float:left; width:120px; height:160px; margin-right:20px }
{% when 'compact' %}
.related-products * { font-size:13px; text-align:center; padding:0 }
.related-products h4 { border:none; margin:5px 0 0 0; line-height:1.5 }
.related-products div.image { height:160px }
.related-products li { float:left; width:180px; height:220px; margin-right:25px }
{% when 'medium' %}
.related-products * { font-size:14px; text-align:center; padding:0 }
.related-products h4 { border:none; margin:10px 0 0 0; line-height:1.8 }
.related-products div.image { height:240px }
.related-products li { float:left; width:260px; height:300px; margin-right:25px }
{% endcase %}
.related-products { overflow:hidden }
.related-products span.money { font-size:0.8em }
.related-products li:last-child { margin-right:0 }
</style>
<script>!window.jQuery && document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"><\/script>')</script>
{{ 'api.jquery.js' | shopify_asset_url | script_tag }}
<script type="text/javascript" charset="utf-8">
//<![CDATA[
var recommendations = [];
{% for tag in product.tags %}
recommendations.push('{{ tag | handle }}');
{% endfor %}
if (recommendations.length) {
var list = jQuery('ul.related-products');
for (var i=0; i<recommendations.length; i++) {
jQuery.getJSON(recommendations[i] + '.js', function(product) {
list.append('<li><div class="image"><img src="' + product.images[0].replace(/(\.jpg|\.png|\.jpeg|\.gif)/, '_{{ image_size }}$1') + '" /></div><h4>' + product.title + '</h4><span class="money">' + Shopify.formatMoney(product.price, "{{ shop.money_format }}") + '</span></li>');
});
}
}
//]]>
</script>
{% endif %}
Reference : https://gist.github.com/carolineschnapp/1002949
Or use paid apps from store.

Shopify - Hiding sold out variants on dropdown (regular solution not working)

On my Shopify store I need to be able to hide sizes in the dropdown that are no longer available. I have tried multiple times adding the code that Shopify suggests here but I am using the Retina Out of the Sandbox theme and add that code to the product-form.liquid file and what happens is only 1 size becomes available no matter what. My store is in dire need of this feature because we sell tons of closeout shoes no longer available so when a customer searches for a size products that have a sold out size 9 still show because it is not hidden on the dropdown, it just says Sold Out, here is my code. Apologies if the formatting is not so nice looking, this is what came with my theme.
product-form.liquid
{% if product.available %}
<form action="/cart/add" method="post" class="clearfix product_form" data-money-format="{{ shop.money_format }}" data-shop-currency="{{ shop.currency }}" id="product-form-{{ product.id }}">
{% if settings.display_inventory_left %}
<div class="items_left">
{% if product.variants.first.inventory_management == "shopify" and product.variants.first.inventory_quantity > 0 %}
<p><em>{{ product.variants.first.inventory_quantity }} {{ settings.inventory_left_text | escape }}</em></p>
{% endif %}
</div>
{% endif %}
{% if product.options.size > 1 %}
<div class="select">
<select id="product-select-{{ product.id }}" name='id'>
{% for variant in product.variants %}
<option {% if variant == product.selected_or_first_available_variant %}selected="selected"{% endif %} value="{{ variant.id }}">{{ variant.title }}</option>
{% endfor %}
</select>
</div>
{% elsif product.options.size == 1 and (product.variants.size > 1 or product.options[0] != "Title") %}
<div class="select">
<label>{{ product.options[0] }}:</label>
<select id="product-select-{{ product.id }}" name='id'>
{% for variant in product.variants %}
<option {% if variant == product.selected_or_first_available_variant %}selected="selected"{% endif %} value="{{ variant.id }}">{{ variant.title }}</option>
{% endfor %}
</select>
</div>
{% else %}
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
{% endif %}
{% if settings.display_product_quantity %}
<div class="left">
<label for="quantity">Quantity:</label>
<input type="number" min="1" size="2" class="quantity" name="quantity" id="quantity" value="1" />
</div>
{% endif %}
<div class="purchase clearfix {% if settings.display_product_quantity %}inline_purchase{% endif %}">
{% if settings.cart_return == 'back' %}
<input type="hidden" name="return_to" value="back" />
{% endif %}
<input type="submit" name="add" value="{{ settings.add_to_cart_text | escape }}" class="action_button add_to_cart" />
</div>
</form>
{% if product.variants.size > 1 or product.options.size > 1 %}
<script type="text/javascript">
// <![CDATA[
$(function() {
$product = $('#product-' + {{ product.id }});
new Shopify.OptionSelectors
("product-select-{{ product.id }}",{
product: {{ product | json }},
onVariantSelected: selectCallback{% if product-form == 'product' %},
enableHistoryState: true{% endif %}
});
{% if product.options.size == 0 %}
{% for variant in product.variants %}
{% unless variant.available %}
jQuery('.single-option-selector option').filter(function() { return jQuery(this).html() === {{ variant.title | json }}; }).remove();
{% endunless %}
{% endfor %}
jQuery('.single-option-selector').trigger('change');
{% endif %}
// ]]>
</script>
{% endif %}
{% endif %}
A couple of small things I noticed:
{% if product.options.size == 0 %} should be {% if product.options.size == 1 %} (see here).
You're missing the closing brackets for $(function() {.... You need }); before the closing </script> tag.
This seems to work for me now:
{% if product.variants.size > 1 or product.options.size > 1 %}
<script type="text/javascript">
// <![CDATA[
$(function() {
$product = $('#product-' + {{ product.id }});
new Shopify.OptionSelectors
("product-select-{{ product.id }}",{
product: {{ product | json }},
onVariantSelected: selectCallback{% if product-form == 'product' %},
enableHistoryState: true{% endif %}
});
{% if product.options.size == 1 %} // *** should be 1, not 0 ***
{% for variant in product.variants %}
{% unless variant.available %}
jQuery('.single-option-selector option').filter(function() { return jQuery(this).html() === {{ variant.title | json }}; }).remove();
{% endunless %}
{% endfor %}
jQuery('.single-option-selector').trigger('change');
{% endif %}
}); // *** missing closing brackets here ***
// ]]>
</script>
{% endif %}