variant.inventory_quanity & selectCallback

Tourist
5 0 1

I have some products/variants that I want to continue selling even after reaching zero inventory as a "pre-sale" on our next inventory delivery. However we also want to provide users with the opportunity to submit their email for a back-in-stock notification if they'd prefer that solution to submitting payment upfront.

The theme i am useing has a select.Callback function and there are other code implementations that trigger on the variant.inventory_quantity variable so i would have thought it would be as simple as the following below the product form

{% if variant.inventory_quantity <= 0 %}
  <div id="back-in-stock">
{% include 'product-back-in-stock-form' %}
  </div>
{% endif %} 

 

However this implementation does not function as intended. The form will only print on page load if the product/variant is out of stock. Then it continues to display even as you switch between in-stock and out-of-stock variants. If the product page loads on a variable that is in stock, the form does not print.

My assumption is that this {% if %} statement is not being affected by the select.Callback function, but I don't quite understand why given that other things in the template seem to work fine with the variant.inventory_quantity variable. I'm not savvy enough with JS to figure it out.

Thanks for the help.

0 Likes
Highlighted
Tourist
5 0 1

For reference here is some liquid from the same template i'm working in that seems to have no problems referencing the variant.inventory_quantity liquid variable 

{% if product.available %}
    {% if settings.display_inventory_left %}
      <div class="items_left">
        {% if variant.inventory_management != blank and variant.inventory_quantity > 0 %}
          {% capture items_left_text %}
            {% if variant.inventory_quantity == 1 %}
              {{ 'products.product.items_left_count.one' | t }}
            {% else %}
              {{ 'products.product.items_left_count.other' | t }}
            {% endif %}
          {% endcapture %}
          {% if variant.inventory_quantity <= settings.inventory_threshold %}
            {{ variant.inventory_quantity }} {{ items_left_text }}
          {% endif %}
        {% endif %}
      </div>
    {% endif %}

 

And I'm feeling like the java variable is somewhere in this neck of the woods.

 

 if (variant) {
    if (variantInventory) {
      variantInventory.forEach(function(v){
        if (v.id === variant.id) {
          variant.inventory_quantity = v.inventory_quantity;
          variant.inventory_management = v.inventory_management;
          variant.inventory_policy = v.inventory_policy;
        }
      });
    }
0 Likes