Commit 3fb0e478 authored by José Luis Uc's avatar José Luis Uc

Agregada opción para eliminar producto desde la vista de purchase

parent 542e40c2
......@@ -119,6 +119,21 @@ function deleteProductCar(element){
});
}
function deleteProductFromShoppingCart(id) {
$.ajax({
type: 'POST',
url: del_prod_cartDB_url,
data:{
'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value,
'id': id
},
dataType: 'json',
success: function (data) {
location.reload();
}
})
}
function drawPolygon(element) {
polygonList.forEach(function (polygon) {
if (polygon.id === element.id) {
......
......@@ -139,6 +139,11 @@
<!-- Main content -->
<section class="content" style="overflow-y: auto; height: 85vh">
<div class="row">
{% if total_products == 0 %}
<div class="col-md-8 col-md-offset-2">
<h2 class="text-center">Your Shopping Cart is empty.</h2>
</div>
{% else %}
<div class="col-md-5 col-md-offset-2">
{% for product in product_list %}
<div class="box box-warning" style="margin-bottom: 10px">
......@@ -149,6 +154,9 @@
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-toggle="tooltip" data-original-title="Delete" onclick="deleteProductFromShoppingCart({{ product.id }})">
<i class="fa fa-trash"></i>
</button>
</div>
</div>
<div class="box-body">
......@@ -201,6 +209,7 @@
</div>
</div>
</div>
{% endif %}
</div>
</section>
<!-- /.content -->
......@@ -255,4 +264,7 @@
{% endblock %}
{% block scripts %}
<!-- page script -->
<script>
var del_prod_cartDB_url = "{% url 'del-cart-rqst' %}";
</script>
{% endblock %}
......@@ -532,7 +532,7 @@ def showCart(request):
user = User.objects.get(id=request.user.id)
prod_list = []
product_list = Purchase.objects.values('user', 'productList', 'purchased', 'price', 'aggreg_date').filter(user=user, purchased=0)
product_list = Purchase.objects.values('user', 'productList', 'purchased', 'price', 'aggreg_date', 'id').filter(user=user, purchased=0)
total_price = 0
total_products = 0
......@@ -542,7 +542,8 @@ def showCart(request):
'purchased': products['purchased'],
'price': products['price'],
'aggreg_date': products['aggreg_date'],
'catalog': product
'catalog': product,
'id': products['id']
})
total_price += products['price']
total_products += 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment