{% extends 'shop/_layouts/main' %} {% set products = craft.products.limit(5).all() %} {% block main %}

Products

{{ redirectInput('shop/cart') }} {{ csrfInput() }} {% for product in products if product.defaultVariant.isAvailable %} {% endfor %}
{% for product in products %}
{% include "shop/_images/product" with { number: '3' } %}

{% if product.url %}{{ product.link }}{% else %}{{ product.title }}{% endif %}

{% if product.getVariants()|length %}
{{ redirectInput('shop/cart') }} {{ csrfInput() }} {% if product.hasUnlimitedStock or (product.hasUnlimitedStock == false and product.totalStock > 0 ) %} {% else %} {{ "Out of Stock"|t }} {% endif %}
{% if currentUser %} {% set order = craft.orders.user(currentUser).hasPurchasables(product.defaultVariant).all() %} {% if order|length %} I already own this product: Order #{{ order[0].shortNumber }} {% endif %} {% endif %} {%- for purchasable in product.getVariants() -%} {%- endfor -%} {% endif %}
{% endfor %} {% set donation = craft.commerce.donation %} {% if donation and donation.isAvailable %}

Donations

{{ redirectInput('shop/cart') }} {{ csrfInput() }}
{% endif %} {% js %} $( ".purchasableId" ).change(function(e) { $(".purchasableInfo").hide(); $("#"+($(this).find(":selected").data('info'))).toggle(); }); {# $('form.add-to-cart-form').submit(function(e){ e.preventDefault(); var purchasable = $(this).find('.purchasableId').val(); $.ajax({ type: "POST", dataType: 'json', headers: { "X-CSRF-Token" : '{{ craft.app.request.csrfToken }}', }, url: '', data: { 'action' : 'commerce/cart/update-cart', 'purchasableId': purchasable, 'note' : 'from ajax' }, success: function(data){ console.log(data); } }); }); #} {% endjs %} {% endblock %}