james-a of Underwaterpistol
12/1/2017 - 11:14 AM

Check for samples in cart and min value

{% assign hassample = false%}
            
{% assign sample_count =  0 | plus:0 %}
{% assign uniqueitem = false %}
            
{% for item in cart.items %}
{% assign itemvendor = item.vendor | downcase %}
    {% if itemvendor contains 'sample service' %}
            {% assign hassample = true %}
            {% assign itemquantity = item.quantity | plus:0%}
                        
            {% if itemquantity > 1 %}
                {% assign uniqueitem = true %}
            {% endif %}

            {% assign sample_count  = sample_count | plus: itemquantity %}  
    {% endif %}
{% endfor %}            

{% if hassample %}

    {% if sample_count >3 %}

        <p>You can only have 3 free samples</p>

    {% else %}

        {% if uniqueitem %}
              <p>Sorry only one unique sample per order</p>
        {% else %}
        
          {% assign minimum = 20 %}
          {% assign price1 = cart.total_price | divided_by: 100 %}
          {% if price1 >= minimum %}
              <input class="action-button n2" type="submit" name="checkout" value="{{ 'cart.submit' | t }}" />
          {% else %}
              <p>Because you have a sample in your cart you can't checkout without £20 in your cart MESSAGE</p>
          {% endif %}

        {% endif %}
    
    {% endif %}

{% else %}
    <input class="action-button n2" type="submit" name="checkout" value="{{ 'cart.submit' | t }}" />
{% endif %}