If statement with two conditions

Solved
Highlighted
Tourist
24 0 1

Current:

 

{% if product.type != 'Event' %}

 

Need to change to this:

 

product.type 'Event' must be 1, is the following what I need?

 

{% if product.type 'Event' == 1 %}

Do stuff

{% endif %}

0 Likes
Astronaut
1007 130 238

I don't understand your question. How can your product type equal a number. Product types generally are something like "t-shirts" or "electronics", how are you expecting to get a number in return?

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
24 0 1

Sorry,

 

I need an if statement to say:

 

In order for the customer to complete an order , an event must be in the cart and you can only have 1 in the cart in order to checkout.

 

I currently have working that as long as an event is in the cart you can proceed to checkout, but my company want to limit the event to one per order.

0 Likes
Astronaut
1007 130 238

You can find the checkout button and inside the button element you can say something like:

 

<button class="checkout" {% if cart.item_count > 1 %} disabled {% endif %}>
Checkout
</button>

This would prevent your form from submitting when pressing the checkout button, and you can put another condition somewhere on the cart page to notify the customer with the same credentials:

 

{% if cart.item_count > 1 %}
 Sorry, you can only order one event at a a time. 
{% endif %}
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
24 0 1

looking for something a little more specific

 

if cart has product type 'Event' >1; disable checkout button, and display message "Only one event per order please."

elseif

 cart has product type 'Event' >0 show checkout btn

 

0 Likes
Astronaut
1007 130 238

You can loop through the line items and assign a variable to be true if the product type == Event. Something like:

 

{% assign event_in_cart = false %}
{% for item in cart.items %} {% assign product_type = item.product.type | handleize %} {% if product_type == "event" and item.quantity > 1 %} {% assign event_in_cart = true %} {% endif %} {% endfor %} <button {% if event_in_cart %}disabled{% endif %}>Checkout</button>

Sorry, forgot the quantity addition. Edited. So this says if the product type is an event and the product quantity is greater than 1, then disable the button

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
24 0 1

Okay I will try this out and get back with you. Thank you for all your help on this.

 

you can see what I am currently working on, its a pain in my butt but its what the company wants.

 

Orders.biomodex.com

 

username: bmxorders@biomodex.com, password: 12345

 

I have disabled checkout for this username so you will be limited on what you can and cannot do/see.

0 Likes

Success.

Astronaut
1007 130 238

Here's an updated code, I neglected to take into account if they have added more than one event. As in multiple events, not just a higher quantity than 1 of the same event:

 

{% assign event_in_cart = false %}
{% assign number_of_events = 0 %}
{% for item in cart.items %}
  {% assign product_type = item.product.type | handleize %}
  {% if product_type == "event" %}
    {% assign event_in_cart = true %}
	{% assign item_quantity = item.quantity %}
	{% assign number_of_events = number_of_events | plus: 1 %}
  {% endif %}
{% endfor %}

<button {% if event_in_cart and number_of_events > 1 %}disabled{% elsif event_in_cart and item_quantity > 1 %}disabled{% endif %}>Checkout</button>

{% if event_in_cart and number_of_events > 1 %}
Please only order 1 event at a time.
{% elsif event_in_cart and item_quantity > 1 %}
Please only order 1 event at a time.
{% endif %}
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
1 Like
Tourist
24 0 1

Now I have to get this to work with my current locksmith lock:

 

Permit if customer is not tagged with "Generic" … and the customer has a product matching "tag:Event" in their cart . Thank you for your help!!!!

0 Likes
Tourist
24 0 1

Here is my solution that works they way I need it to:

 

{% assign event_in_cart = false %}
{% assign number_of_events = 0 %}
{% for item in cart.items %}
{% assign product_type = item.product.type | handleize %}
{% if product_type == "event" %}
{% assign event_in_cart = true %}
{% assign item_quantity = item.quantity %}
{% assign number_of_events = number_of_events | plus: 1 %}
{% endif %}
{% endfor %}

          {% if event_in_cart and number_of_events > 1 %}
          <font color="Red">You may only order 1 event at a time.</font>
          {% elsif event_in_cart and item_quantity > 1 %}
             <font color="Red">You may only order 1 event at a time.</font>
          
          {% elsif locksmith_access_granted %}
            
          
          <button type="submit" name="checkout" class="btn">
            <span class="icon icon-cart"></span>
            {{ 'cart.general.checkout' | t }}
          </button>
          
          {% else %}
          <font color="Red"> <h4>To complete your order you must complete Step 1 and add an Event to your cart. If you still see this message then you do not have the correct permissions to purchase.</h4> </font>
          
          {% endif%}
1 Like