How can I simultaneously check for digital and physical products in Cart.js?

How can I simultaneously check for digital and physical products in Cart.js?

pokornyib
Visitor
1 0 0

Hi All!

I would like to check whether there are digital and physical products at the same time in the cart and block checkout. 

 

I have tried to do it in main-cart-items liquid, but since it's checked only at page load, it gives the same error message if some products are already deleted from the cart. I have tried something like this:

{% assign physical_products = 0 %}
{% assign digital_products = 0 %}
{% for item in cart.items %}
  {% if item.requires_shipping %}
    {% assign physical_products = physical_products  | plus : 1 %}
  {% else %}
    {% assign digital_products = digital_products | plus : 1 %}
  {% endif %}      
{% endfor %}
{% if digital_products > 0 and physical_products > 0 %}
<p>Physical and digital products can be purchased in the same order!</p>
{% endif %}

So, it works, but the error is not gone if the products are deleted from the cart, only after refreshing the page.

Can I make this method work somehow?

 

 

So, I thought I add the check to cart.js and check when clicking on the checkout button, but I can't figure out how to iterate the cart items in cart.js. 

Any suggestions?

 

Thank you in advance!

 

 

Replies 0 (0)