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

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

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

{% block main %}
{% if request.cart.has_items %}
<form method="post" class="form-cart form-shop">
{% csrf_token %}
{% for error in cart_formset.errors %}
{% if error.values.0 %}{{ error.values.0 }}{% endif %}
{% endfor %}
{{ cart_formset.management_form }}
<table class="table table-striped">
	<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>
    {% 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>
</table>
<div class="form-actions clearfix">
    <div class="form-actions-wrap">
    <a href="{% url "shop_checkout" %}" class="btn btn-primary btn-large">
        {% 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-large" value="{% trans "Update Cart" %}">
    </div>
</div>
</form>

{% if discount_form %}
<form method="post" class="discount-form form-horizontal">
    {% fields_for discount_form %}
    <input type="submit" class="btn" style="float:right" value="{% trans 'Apply' %}">
</form>
{% endif %}

{% with request.cart.upsell_products as upsell_products %}
{% if upsell_products %}
<h2>{% trans "You may also like:" %}</h2>
<ul id="related-products" class="thumbnails">
    {% for product in upsell_products %}
    <li>
        <a class="thumbnail" href="{{ product.get_absolute_url }}">
            <div class="img">
	            {% if product.image %}
	            <img src="{{ MEDIA_URL }}{% thumbnail product.image 90 90 %}" />
	            {% endif %}
            </div>
            <h6>{{ product }}</h6>
            {% if product.has_price %}
                {% if product.on_sale %}
                <span class="old-price">{{ product.unit_price|currency }}</span>
                {% endif %}
                <span class="price">{{ product.price|currency }}</span>
            {% endif %}
        </a>
    </li>
    {% endfor %}
</ul>
{% endif %}
{% endwith %}

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