{% extends "shop/base.html" %}
{% load mezzanine_tags shop_tags i18n %}

{% block meta_title %}{% trans "Your Cart" %}{% endblock %}
{% block title %}{% trans "Your Cart" %}{% endblock %}
{% block body_id %}cart{% endblock %}

{% block breadcrumb_menu %}
{{ block.super }}
<li>{% trans "Your Cart" %}</li>
{% endblock %}

{% block main %}
{% if cart_formset.forms %}
<form method="post" class="cart-form">
{% csrf_token %}
{% if cart_formset.errors %}
{% for error in cart_formset.errors %}
{% if error.values.0 %}{{ error.values.0 }}{% endif %}
{% endfor %}
{% endif %}
{{ cart_formset.management_form }}
<table class="table table-striped">
    <thead>
    <tr>
        <th colspan="2" class="left">{% trans "Item" %}</th>
        <th>{% trans "Unit Price" %}</th>
        <th class="center">{% trans "Qty" %}</th>
        <th>{% trans "Price" %}</th>
        <th class="center">{% trans "Remove?" %}</th>
    </tr>
    </thead>
    <tbody>
    {% for form in cart_formset.forms %}
    {% with form.instance as item %}
    <tr>
        <td width="30">
            {{ form.id }}
            {% if item.image %}
            <a href="{{ item.get_absolute_url }}">
                <img alt="{{ item.description }}" src="{{ MEDIA_URL }}{% thumbnail item.image 30 30 %}">
            </a>
            {% endif %}
        </td>
        <td class="left">
            <a href="{{ item.get_absolute_url }}">{{ item.description }}</a>
        </td>
        <td>{{ item.unit_price|currency }}</td>
        <td class="quantity">{{ form.quantity }}</td>
        <td>{{ item.total_price|currency }}</td>
        <td class="center">{{ form.DELETE }}</td>
    </tr>
    {% endwith %}
    {% endfor %}
    <tr>
        <td colspan="5">{% order_totals %}</td>
        <td>&nbsp;</td>
    </tr>
    </tbody>
</table>

<div class="form-actions">
    <a href="{% url "shop_checkout" %}" class="btn btn-primary btn-lg pull-right">
        {% if request.session.order.step %}{% trans "Return to Checkout" %}{% else %}{% trans "Go to Checkout" %}{% endif %}
    </a>
    <input type="submit" name="update_cart" class="btn btn-default btn-lg pull-left" value="{% trans "Update Cart" %}">
</div>
</form>

{% if discount_form %}
<form method="post" class="discount-form col-md-12 text-right">
    {% fields_for discount_form %}
    <input type="submit" class="btn btn-default" value="{% trans "Apply" %}">
</form>
{% endif %}

{% if settings.SHOP_USE_UPSELL_PRODUCTS %}
{% with request.cart.upsell_products as upsell_products %}
{% if upsell_products %}
<h2>{% trans "You may also like:" %}</h2>
<div class="row">
    {% for product in upsell_products %}
    <div class="col-xs-6 col-sm-4 col-md-3 product-thumb">
        <a class="thumbnail" href="{{ product.get_absolute_url }}">
            {% if product.image %}
            <img src="{{ MEDIA_URL }}{% thumbnail product.image 90 90 %}">
            {% endif %}
            <div class="caption">
            <h6>{{ product }}</h6>
            <div class="price-info">
            {% if product.has_price %}
                {% if product.on_sale %}
                <span class="old-price">{{ product.unit_price|currency }}</span>
                {% trans "On sale:" %}
                {% endif %}
                <span class="price">{{ product.price|currency }}</span>
            {% else %}
                <span class="coming-soon">{% trans "Coming soon" %}</span>
            {% endif %}
            </div>
            </div>
        </a>
    </div>
    {% endfor %}
</div>
{% endif %}
{% endwith %}
{% endif %}

{% else %}
<p>{% trans "Your Cart is empty." %}</p>
{% endif %}
{% endblock %}
