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){ ...@@ -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) { function drawPolygon(element) {
polygonList.forEach(function (polygon) { polygonList.forEach(function (polygon) {
if (polygon.id === element.id) { if (polygon.id === element.id) {
......
...@@ -139,6 +139,11 @@ ...@@ -139,6 +139,11 @@
<!-- Main content --> <!-- Main content -->
<section class="content" style="overflow-y: auto; height: 85vh"> <section class="content" style="overflow-y: auto; height: 85vh">
<div class="row"> <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"> <div class="col-md-5 col-md-offset-2">
{% for product in product_list %} {% for product in product_list %}
<div class="box box-warning" style="margin-bottom: 10px"> <div class="box box-warning" style="margin-bottom: 10px">
...@@ -149,6 +154,9 @@ ...@@ -149,6 +154,9 @@
<button type="button" class="btn btn-box-tool" data-widget="collapse"> <button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-minus"></i> <i class="fa fa-minus"></i>
</button> </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> </div>
<div class="box-body"> <div class="box-body">
...@@ -201,6 +209,7 @@ ...@@ -201,6 +209,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</section> </section>
<!-- /.content --> <!-- /.content -->
...@@ -255,4 +264,7 @@ ...@@ -255,4 +264,7 @@
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<!-- page script --> <!-- page script -->
<script>
var del_prod_cartDB_url = "{% url 'del-cart-rqst' %}";
</script>
{% endblock %} {% endblock %}
...@@ -532,7 +532,7 @@ def showCart(request): ...@@ -532,7 +532,7 @@ def showCart(request):
user = User.objects.get(id=request.user.id) user = User.objects.get(id=request.user.id)
prod_list = [] 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_price = 0
total_products = 0 total_products = 0
...@@ -542,7 +542,8 @@ def showCart(request): ...@@ -542,7 +542,8 @@ def showCart(request):
'purchased': products['purchased'], 'purchased': products['purchased'],
'price': products['price'], 'price': products['price'],
'aggreg_date': products['aggreg_date'], 'aggreg_date': products['aggreg_date'],
'catalog': product 'catalog': product,
'id': products['id']
}) })
total_price += products['price'] total_price += products['price']
total_products += 1 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