diff --git a/alkatorapi/migrations/0022_product_hidden.py b/alkatorapi/migrations/0022_product_hidden.py new file mode 100644 index 0000000..941baac --- /dev/null +++ b/alkatorapi/migrations/0022_product_hidden.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.12 on 2024-10-14 07:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('alkatorapi', '0021_alter_cart_user'), + ] + + operations = [ + migrations.AddField( + model_name='product', + name='hidden', + field=models.BooleanField(default=False), + ), + ] diff --git a/alkatorapi/models.py b/alkatorapi/models.py index 9fe9dfc..527d6a9 100644 --- a/alkatorapi/models.py +++ b/alkatorapi/models.py @@ -69,6 +69,7 @@ class Product(models.Model): description = models.TextField() img = models.ImageField(upload_to="photos") price = models.IntegerField() + hidden = models.BooleanField(default=False) quantity = models.IntegerField() def __str__(self): diff --git a/alkatorapi/views.py b/alkatorapi/views.py index c5c1290..d578f64 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -343,13 +343,15 @@ def products(request): 'price': product.price, 'quantity': product.quantity, } - for product in Product.objects.all()[1:] if product.quantity > 0 + for product in Product.objects.all() if product.quantity > 0 and not product.hidden ]), content_type='application/json') def cart_add(request): _id = request.GET['id'] user = request.user + if not user.is_authenticated: + return HttpResponse('{"status": "failed", "reason": "Pro využivání Košíku je třeba se přihlásit!"}') try: cart = user.cart except AttributeError: diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index d31acd5..09f4c8a 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -112,6 +112,9 @@ class Main extends Component { } }) } + calculateTotalPrice(){ + return this.state.cart.reduce((acc, cur) => acc + cur.price * cur.quantity, 0) + } decreaseInCart(product){ fetch(addr_prefix + "/api/cart/decrease?id=" + product.id).then(resp => resp.json()).then(json=>{ if(json.status == "failed"){ @@ -286,7 +289,7 @@ class Main extends Component {
} - {Object.keys(this.state.login_status).length > 0 && this.state.products.length > 0 && + {this.state.products.length > 0 &&