{% 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() }} {% for purchasable in product.getVariants() %}
{{ purchasable.sku }} {{ purchasable.description }} {% if purchasable.onSale %} {{ purchasable.price|commerceCurrency(cart.currency) }} {% endif %} {{ purchasable.salePrice|commerceCurrency(cart.currency) }}
Stock: {% if purchasable.hasUnlimitedStock %}Unlimited{% else %}{{ purchasable.stock }} Remaining{% endif %}
{% for sale in purchasable.sales %} {% if loop.first %}Sales:{% endif %} {{ sale.name }}{% if not loop.last %}, {% endif %} {% endfor %}
{% if currentUser %} {% set orders = craft.orders.user(currentUser).isCompleted(true).hasPurchasables(purchasable).all() %} {% for order in orders %} {% if loop.first %}Purchased:{% endif %} #{{ order.reference|upper }}{% if not loop.last %}, {% else %}
{% endif %} {% endfor %} {% endif %}
{% endfor %}
{% endif %}
{% endfor %} {% js %} {# $('form.add-to-cart-form').submit(function(e){ e.preventDefault(); var purchasable = $(this).find('.js-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 %}