Updating Qty of All Line Items on Cart page

Tyler_H
Shopify Partner
2 0 0

When I go to update the QTY (plus or minus) of one line item on the cart page - it is updating the QTY of ALL line items instead of just the one I selected. Is there an issue with my code. I do have a wholesale plugin so apologies for the lengthly code.

The cart.liquid code

 

<form action="/cart" method="post" novalidate class="cart table-wrap">

<div id="carter" >
  <div class="cart-contents">
    <h1>Your Bag</h1>
      {% if cart.item_count > 0 %}
      {% for item in cart.items %}
{% comment %} Wholesale_Club_Item_Prices Start {% endcomment %}
{% if item.product %}{% assign base_product = item.product %}{% else %}{% assign base_product = item %}{% endif %}
{% if item.variant %}{% assign base_variant = item.variant %}{% else %}{% assign base_variant = item.selected_or_first_available_variant %}{% endif %}

{% if shop.metafields.sawholesale['base_price'] == blank %}
  {% assign base_price = 'compare_at_price' %}
{% else %}
  {% assign base_price = shop.metafields.sawholesale['base_price'] %}
{% endif %}

{% assign saw_discount = 0 %}{% assign saw_has_discount = false %}

{% if customer.tags != blank %}
  {% for mf in base_product.metafields.sawholesale %}
    {% capture product_customer_tag %}{{ mf | first | replace: 'discount_', '' }}{% endcapture %}
    {% if customer.tags contains product_customer_tag %}
      {% assign saw_has_discount = true %}
      {% assign discount_key = product_customer_tag | prepend: 'discount_' %}
      {% assign price_key = product_customer_tag | prepend: 'price_' %}
      {% assign saw_discount = base_product.metafields.sawholesale[discount_key] | divided_by: 100.0 %}
    {% endif %}
  {% endfor %}
{% endif %}

{% assign saw_discount = 1 | minus: saw_discount %}

{% if base_price == 'price' or base_variant.compare_at_price == blank  or base_variant.compare_at_price == 0 or base_variant.compare_at_price < base_variant.price %}
  {% assign saw_variant_compare_at_price = base_variant.price %}
{% else %}
  {% assign saw_variant_compare_at_price = base_variant.compare_at_price %}
{% endif %}

{% assign cpe = shop.metafields.sawholesale['cpe'] | default: "true" %}
{% if base_variant.metafields.sawholesale[price_key] != blank and cpe == "true" %}
  {% assign saw_variant_price = base_variant.metafields.sawholesale[price_key] %}
{% else %}
  {% assign saw_variant_price = saw_variant_compare_at_price | times: saw_discount %}
{% endif %}

{% if saw_has_discount == false or saw_variant_price >= saw_variant_compare_at_price %}
  {% assign WCItem_OriginalPrice = item.original_price %}
  {% assign WCItem_FinalPrice = item.final_price %}
  {% assign WCItem_Price = item.price %}
  {% assign WCItem_PriceMin = item.price_min %}
  {% assign WCItem_PriceMax = item.price_max %}
  {% assign WCItem_CompareAtPrice = item.compare_at_price %}
  {% assign WCItem_CompareAtPriceMin = item.compare_at_price_min %}
  {% assign WCItem_CompareAtPriceMax = item.compare_at_price_max %}
  {% assign WCItem_OriginalLinePrice = item.original_line_price %}
  {% assign WCItem_FinalLinePrice = item.final_line_price %}
  {% assign WCItem_LinePrice = item.line_price %}
{% else %}
  {% assign WCItem_OriginalPrice = saw_variant_compare_at_price %}
  {% assign WCItem_FinalPrice = saw_variant_price %}
  {% assign WCItem_Price = saw_variant_price %}
  {% assign WCItem_PriceMin = item.price_min | times: saw_discount %}
  {% assign WCItem_PriceMax = item.price_max | times: saw_discount %}
  {% assign WCItem_CompareAtPrice = saw_variant_compare_at_price %}
  {% if base_product.compare_at_price_min != 0 %}{% assign WCItem_CompareAtPriceMin = base_product.compare_at_price_min %}{% else %}{% assign WCItem_CompareAtPriceMin = base_product.price_min %}{% endif %}
  {% if base_product.compare_at_price_max != 0 %}{% assign WCItem_CompareAtPriceMax = base_product.compare_at_price_max %}{% else %}{% assign WCItem_CompareAtPriceMax = base_product.price_max %}{% endif %}
  {% assign WCItem_OriginalLinePrice = WCItem_OriginalPrice | round | times: item.quantity %}
  {% assign WCItem_FinalLinePrice = WCItem_FinalPrice | round | times: item.quantity %}
  {% assign WCItem_LinePrice = WCItem_Price | round | times: item.quantity %}
{% endif %}
{% comment %} Wholesale_Club_Item_Prices End {% endcomment %}

      {% include 'cart-item' %}
      {% endfor %}
      {% else %}
      <p style="padding-bottom: 30px;font-size: 21px;">Your bag is current empty.</p>
      <a class="btn coral" onclick="determinePath()">Keep Shopping</a>
      {% endif %}
      {% if cart.item_count > 0 %}
      {% endif %}
    </div>
    {% if cart.item_count > 0 %}
    <div class="cartSum">
      <div class="container">
        <div class="top">
          <h2>Cart Summary</h2>
          <p class="subtle">
            {{cart.item_count}} Items
          </p>
        </div>
        <ul>
            <li>Subtotal <span style="display: block; text-align: right;" class="saw-extra-note"></span><span class="saw-cart-original-total"><p style="opacity:0.6;">{{ cart.total_price | money }}</p></span><span class="saw-cart-total"></span></li>
            <li>Shipping <p class="float">-</p></li>
            <li>Tax <p class="float">-</p></li>
        </ul>
        <li class="est">Estimated Total<span style="display: block; text-align: right;" class="saw-extra-note"></span><span class="saw-cart-original-total"><p style="opacity:0.6;">{{ cart.total_price | money }}</p></span><span class="saw-cart-total"></span></li>
        <label class="gift-select"><input id="gift-select" type="checkbox" name="checkbox" value="value">This is a gift (gift message)</label>
        <div class="regNotes">
          <p class="cart-attribute__field">
            <label for="custom-order-message">Custom Order Message</label>
            <textarea maxlength="250" id="custom-order-message" name="attributes[Custom Order Message]">{{ cart.attributes["Custom Order Message"] }}</textarea>
          </p>
        </div>
        <div class="fundNotes hide">
    <label for="CartSpecialInstructions">Specify Fundraiser Credit</label>
    <textarea maxlength="250" name="note" class="input-full" id="CartSpecialInstructions">{{ cart.note }}</textarea>
  </div>
         <br> {% render 'saw_netterms' %} <br>
        <button type="submit" name="checkout" class="btn orange">{{ 'cart.general.checkout' | t }}</button>
             <br><br><button type="submit" name="update" class="btn white update-cart">Update Totals</button>
      </div>

    </div>
    {% endif %}
</div>
</form>

<style>

#PageContainer {
    background: whitesmoke;
}

</style>

{% render 'wc_cart' %}

 

 

The cart-item.liquid code

 

 

<div class="flex-container cart-item">
    <div class="remove-item">
      <a class="remove" href="/cart/change?line={{ forloop.index }}&quantity=0" rel="{{ item.id }}"><i class="fas fa-times"></i></a>
    </div>
    <img src="{{ item | img_url: 'medium' }}" />
      <div class="prodinfo">
        <h3>{{item.product.title}}</h3>
        <p class="price">{{item.variant.price | money}}</p>
        {% assign property_size = item.properties | size %}
        {% if property_size > 0 %}
          {% for p in item.properties %}
            {% assign first_character_in_key = p.first | truncate: 1, '' %}
            {% unless p.last == blank or first_character_in_key == '_' %}
              <h4><span class="fundCard">Fundraiser</span>: {{ p.last }}</h4>
              {% if p.last contains '/uploads/' %}
                <a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
              {% else %}

              {% endif %}
              <br>
            {% endunless %}
          {% endfor %}
        {% endif %}
        <div class="qty">
          <p>QTY</p>
          <span class="decrease noselect">-</span>
          <input type="number" name="updates[]" id="updates_{{ item.id }}" class="noselect" data-id="{{ item.id }}" value="{{ item.quantity }}" min="0">
          <span class="increase noselect">+</span>
        </div>
      </div>

    </div>

 

 

0 Likes
Tyler_H
Shopify Partner
2 0 0

Here is my js for the QTY selector

$(".increase").click(function() {
  $("input").val(function(i, oldval) {
    return ++oldval;
  });
});

$(".decrease").click(function() {
  $("input").val(function(i, oldval) {
    if (oldval > 1) {
      return --oldval;
    } else {
      return oldval;
    }
  });
});
0 Likes