Product page says it's out of stock when first opened even though quantity isn't being tracked

Highlighted
New Member
2 0 0

Link to product page: https://www.beyondthestars.ph/products/customized-star-map

In the backend, I set the item to not track quantity however for some reason, it still displays as out of stock when opening the product page. Selecting a variant however does make it show as available, including the initial variant. Perhaps there's something I'm missing in the code? I basically made a new `product-template.liquid` file and inserted just this bit from the original `product-template.liquid` I've already tried calling programmatically calling `click()` on one of the variants but it won't work. Any ideas?


 

 

<!--


<meta itemprop="priceCurrency" content="{{ cart.currency.iso_code }}">
<link itemprop="availability" href="http://schema.org/{% if product.available %}InStock{% else %}OutOfStock{% endif %}">

{% capture "form_classes" %}
product-single__form{% if product.has_only_default_variant %} product-single__form--no-variants{% endif %}
{%- endcapture %}

{% capture "form_id" %}AddToCartForm--{{ section.id }}{%- endcapture %}

{% form 'product', product, class:form_classes, id:form_id, data-product-form: '' %}
{% unless product.has_only_default_variant %}
{% for option in product.options_with_values %}
{% if option.name != 'Style' %}
<div class="radio-wrapper js product-form__item">
<label class="single-option-radio__label"
for="ProductSelect-option-{{ forloop.index0 }}">
{{ option.name | escape }}
</label>
{% if section.settings.product_selector == 'radio' %}
<fieldset class="single-option-radio"
id="ProductSelect-option-{{ forloop.index0 }}">
{% assign option_index = forloop.index %}
{% for value in option.values %}
{% assign variant_label_state = true %}
{% if product.options.size == 1 %}
{% unless product.variants[forloop.index0].available %}
{% assign variant_label_state = false %}
{% endunless %}
{% endif %}
<input type="radio"
{% if option.selected_value == value %} checked="checked"{% endif %}
{% unless variant_label_state %} disabled="disabled"{% endunless %}
value="{{ value | escape }}"
data-index="option{{ option_index }}"
name="option{{ option.position }}"
class="single-option-selector__radio{% unless variant_label_state %} disabled{% endunless %}"
id="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}">
<label for="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}"{% unless variant_label_state %} class="disabled"{% endunless %} style="line-height: 20px;">
{{ value | escape }}<br>
{% for vari in product.variants %}
{% if vari.option1 == value %}
{{ vari.price | money }}
{% endif %}
{% endfor %}

</label>
{% endfor %}
</fieldset>
{% else %}
<select class="single-option-selector__radio 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 | escape }}</option>
{% endfor %}
</select>
{% endif %}
</div>
{% endif %}
{% endfor %}
{% endunless %}

<select name="id" id="ProductSelect--{{ section.id }}" class="product-single__variants no-js">
{% for variant in product.variants %}
{% if variant.available %}
<option {% if variant == product.selected_or_first_available_variant %}
selected="selected" {% endif %}
data-sku="{{ variant.sku }}"
value="{{ variant.id }}">
{{ variant.title }} - {{ variant.price | money_with_currency }}
</option>
{% else %}
<option disabled="disabled">
{{ variant.title }} - {{ 'products.product.sold_out' | t }}
</option>
{% endif %}
{% endfor %}
</select>


<!-- Starmap Details -->
<input required id="hiLatitude" type="text" name="properties[Latitude]" hidden="hidden" value="10">
<input required id="hiLongitude" type="text" name="properties[Longitude]" hidden="hidden" value="10">
<input required id="hiHeader" type="text" name="properties[Header]" hidden="hidden" value="Default Header">
<input required id="hiSubheader" type="text" name="properties[Subheader]" hidden="hidden" value="Default Sub">
<input required id="hiTemplate" type="text" name="properties[Template]" hidden="hidden" value="compass_light">

{% if section.settings.quantity_enabled %}
<div class="product-single__quantity">
<label for="Quantity" class="product-single__quantity-label js-quantity-selector">{{ 'products.product.quantity' | t }}</label>
<input type="number" hidden="hidden" id="Quantity" name="quantity" value="1" min="1" class="js-quantity-selector">
</div>
{% endif %}

<div class="product-single__add-to-cart{% if section.settings.add_to_cart_button_size == 'large' %} product-single__add-to-cart--full-width{% endif %}">
<button type="submit" name="add" id="AddToCart--{{ section.id }}" class="btn btn--add-to-cart{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"{% unless current_variant.available %} disabled="disabled"{% endunless %}>
<span class="btn__text">
{% if current_variant.available %}
{{ 'products.product.add_to_cart' | t }}
{% else %}
{{ 'products.product.sold_out' | t }}
{% endif %}
</span>
</button>
{% if section.settings.enable_payment_button %}
{{ form | payment_button }}
{% endif %}
</div>

{% endform %}

 

-->

 

 

0 Likes
Highlighted
New Member
2 0 0

In case anyone else runs into the same issue, here's what I did

I took another look at the `add to cart` button and realized it was being assigned according to `current_variant`  however it wasn't being assigned anywhere in my new .liquid file.

{% if current_variant.available %}
{{ 'products.product.add_to_cart' | t }}
{% else %}
{{ 'products.product.sold_out' | t }}
{% endif %}

So I took a look at the original and found this line

{% assign current_variant = product.selected_or_first_available_variant %}

I copied this into my .liquid file and it started working perfectly again! 

0 Likes