From 3a8ffd73c57b52229fbe7a7e362b6e9a09dd71c3 Mon Sep 17 00:00:00 2001 From: mtyton Date: Fri, 21 Jul 2023 21:34:37 +0200 Subject: [PATCH] configurator is finished summary page has been added --- artel/docker-compose.yml | 3 ++ .../0012_order_uuid_product_uuid.py | 23 ++++++++++++++ artel/store/models.py | 3 ++ artel/store/static/js/cart.js | 2 +- .../store/configure_product_summary.html | 29 +++++++++++++++-- .../store/templates/store/order_success.html | 31 +++++++++++++++++++ .../templates/store/partials/cart_item.html | 2 +- .../store/partials/summary_cart_item.html | 2 +- artel/store/urls.py | 3 +- artel/store/views.py | 28 ++++++++++++++--- 10 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 artel/store/migrations/0012_order_uuid_product_uuid.py create mode 100644 artel/store/templates/store/order_success.html diff --git a/artel/docker-compose.yml b/artel/docker-compose.yml index 280cffa..7ea367e 100644 --- a/artel/docker-compose.yml +++ b/artel/docker-compose.yml @@ -6,6 +6,9 @@ services: - "1025:1025" - "8025:8025" comfy: + depends_on: + - smtp-server + - db build: dockerfile: Dockerfile.local context: ./ diff --git a/artel/store/migrations/0012_order_uuid_product_uuid.py b/artel/store/migrations/0012_order_uuid_product_uuid.py new file mode 100644 index 0000000..48b4604 --- /dev/null +++ b/artel/store/migrations/0012_order_uuid_product_uuid.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.9 on 2023-07-20 16:50 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + dependencies = [ + ("store", "0011_productparam_delete_templateparamvalue_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="order", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, editable=False), + ), + migrations.AddField( + model_name="product", + name="uuid", + field=models.UUIDField(default=uuid.uuid4, editable=False), + ), + ] diff --git a/artel/store/models.py b/artel/store/models.py index eb85f28..ad9890b 100644 --- a/artel/store/models.py +++ b/artel/store/models.py @@ -1,6 +1,7 @@ import pdfkit import datetime import builtins +import uuid from decimal import Decimal from typing import ( @@ -202,6 +203,7 @@ class Product(ClusterableModel): ) price = models.FloatField() available = models.BooleanField(default=True) + uuid = models.UUIDField(default=uuid.uuid4, editable=False) objects = ProductManager() @@ -439,6 +441,7 @@ class Order(models.Model): sent = models.BooleanField(default=False) order_number = models.CharField(max_length=255, null=True) + uuid = models.UUIDField(default=uuid.uuid4, editable=False) objects = OrderManager() @property diff --git a/artel/store/static/js/cart.js b/artel/store/static/js/cart.js index 0d40000..b0c1261 100644 --- a/artel/store/static/js/cart.js +++ b/artel/store/static/js/cart.js @@ -10,7 +10,7 @@ $(document).on('click', '.add-to-cart-button', function(event) { const csrfToken = $(this).data('csrf-token'); console.log(productID); formData.append('product_id', productID); - formData.append('quantity', quantity); // Serialize the form data correctly + formData.append('quantity', 1); // Serialize the form data correctly button.prop('disabled', true); $.ajax({ type: 'POST', diff --git a/artel/store/templates/store/configure_product_summary.html b/artel/store/templates/store/configure_product_summary.html index 59e9b4d..6707231 100644 --- a/artel/store/templates/store/configure_product_summary.html +++ b/artel/store/templates/store/configure_product_summary.html @@ -1,6 +1,27 @@ {% extends 'base.html' %} {% block content %} + + +
+ Wróć do konfiguratora +
+
@@ -38,9 +59,13 @@ {% endif %}
- Wróć do konfiguratora + {% if variant.available %} - + {% else %} {% endif %} diff --git a/artel/store/templates/store/order_success.html b/artel/store/templates/store/order_success.html new file mode 100644 index 0000000..58f3ebc --- /dev/null +++ b/artel/store/templates/store/order_success.html @@ -0,0 +1,31 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+
+ + + + +
+
+

Dziękujemy za zakup!

+
+ Twoje zamówienia zostały przekazane do realizacji. + Oczekuj maili z dokumentami to zamówień.
+ + Twoje numery zamówień: +
+ {% for order in orders %} +
{{order.order_number}}
+ {% endfor %} +
+ +
+ Powrót do sklepu +
+
+{% endblock %} \ No newline at end of file diff --git a/artel/store/templates/store/partials/cart_item.html b/artel/store/templates/store/partials/cart_item.html index 52c2c41..c2be5d9 100644 --- a/artel/store/templates/store/partials/cart_item.html +++ b/artel/store/templates/store/partials/cart_item.html @@ -5,7 +5,7 @@
diff --git a/artel/store/templates/store/partials/summary_cart_item.html b/artel/store/templates/store/partials/summary_cart_item.html index 662af8a..1d7b68e 100644 --- a/artel/store/templates/store/partials/summary_cart_item.html +++ b/artel/store/templates/store/partials/summary_cart_item.html @@ -5,7 +5,7 @@
diff --git a/artel/store/urls.py b/artel/store/urls.py index 7e181a9..193d724 100644 --- a/artel/store/urls.py +++ b/artel/store/urls.py @@ -13,5 +13,6 @@ urlpatterns = [ path('product-configure/summary//', store_views.ConfigureProductSummaryView.as_view(), name='configure-product-summary'), path('cart/', store_views.CartView.as_view(), name='cart'), path("order/", store_views.OrderView.as_view(), name="order"), - path("order/confirm/", store_views.OrderConfirmView.as_view(), name="order-confirm") + path("order/confirm/", store_views.OrderConfirmView.as_view(), name="order-confirm"), + path("order/success/", store_views.OrderSuccessView.as_view(), name="order-success") ] + router.urls diff --git a/artel/store/views.py b/artel/store/views.py index c499d15..2609d47 100644 --- a/artel/store/views.py +++ b/artel/store/views.py @@ -26,7 +26,7 @@ from store.models import ( Order, Product, ProductTemplate, - ProductCategoryParamValue + ProductListPage ) @@ -127,9 +127,11 @@ class ConfigureProductSummaryView(View): def get(self, request, variant_pk: int, *args, **kwargs): variant = Product.objects.get(pk=variant_pk) + context = { "variant": variant, - "params_values": variant.params.all() + "params_values": variant.params.all(), + "store_url": ProductListPage.objects.first().get_url() } return render(request, self.template_name, context) @@ -186,11 +188,27 @@ class OrderConfirmView(View): def post(self, request): customer_data = request.session["customer_data"] cart = SessionCart(self.request) - Order.objects.create_from_cart( + order = Order.objects.create_from_cart( cart.get_items(), None, customer_data ) request.session.pop("customer_data") cart.clear() - messages.success(request, "Zamówienie zostało złożone, sprawdź swój email.") - return HttpResponseRedirect(reverse("cart")) + request.session["order_uuids"] = [str(elem) for elem in order.values_list("uuid", flat=True)] + return HttpResponseRedirect(reverse("order-success")) + + +class OrderSuccessView(View): + template_name = "store/order_success.html" + + def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: + return { + "orders": Order.objects.filter(uuid__in=self.request.session.get("order_uuids")), + "store_url": ProductListPage.objects.first().get_url() + } + + def get(self, request, *args, **kwargs): + if not self.request.session.get("order_uuids"): + return HttpResponseRedirect(reverse("cart")) + + return render(request, self.template_name, self.get_context_data())