diff --git a/src/core/migrations/0028_order_subscription_description.py b/src/core/migrations/0028_order_subscription_description.py new file mode 100644 index 0000000..eae54d8 --- /dev/null +++ b/src/core/migrations/0028_order_subscription_description.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.2 on 2022-12-30 21:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0027_order_subscription'), + ] + + operations = [ + migrations.AddField( + model_name='order', + name='subscription_description', + field=models.CharField(blank=True, max_length=500), + ), + ] diff --git a/src/core/models.py b/src/core/models.py index 3323210..8bf6cab 100644 --- a/src/core/models.py +++ b/src/core/models.py @@ -389,6 +389,7 @@ class Order(models.Model): null=True, on_delete=models.SET_NULL ) + subscription_description = models.CharField(max_length=500, blank=True) created_at = models.DateTimeField(auto_now_add=True, editable=False) updated_at = models.DateTimeField(auto_now=True) @@ -570,6 +571,7 @@ class Subscription(models.Model): for x in data: if 'Coffee' in x['description']: subscription['unit_price'] = self.convert_int_to_decimal(x['price']['unit_amount']) + subscription['description'] = x['description'] if 'Shipping' in x['description']: subscription['shipping_cost'] = self.convert_int_to_decimal(x['amount']) @@ -590,7 +592,8 @@ class Subscription(models.Model): shipping_total=subscription['shipping_cost'], total_amount=self.convert_int_to_decimal(data_object['total']), weight=self.total_weight, - subscription=self + subscription=self, + subscription_description=subscription['description'] ) bulk_lines = [OrderLine( diff --git a/src/dashboard/templates/dashboard/order_detail.html b/src/dashboard/templates/dashboard/order_detail.html index bdb4a43..625b206 100644 --- a/src/dashboard/templates/dashboard/order_detail.html +++ b/src/dashboard/templates/dashboard/order_detail.html @@ -13,6 +13,11 @@ {{order.get_status_display}} ({{order.total_quantity_fulfilled}} / {{order.total_quantity_ordered}}) + {% if order.subscription %} +
+

Subscription: {{ order.subscription_description }}


+
+ {% endif %}
Product diff --git a/src/dashboard/templates/dashboard/order_list.html b/src/dashboard/templates/dashboard/order_list.html index 05a2c2d..95abd04 100644 --- a/src/dashboard/templates/dashboard/order_list.html +++ b/src/dashboard/templates/dashboard/order_list.html @@ -16,7 +16,7 @@
{% for order in order_list %} - #{{order.pk}} + #{{order.pk}} {% if order.subscription %}(subscription){% endif %} {{order.created_at|date:"D, M j Y"}} {{order.customer.get_full_name}} diff --git a/src/storefront/templates/storefront/customer_detail.html b/src/storefront/templates/storefront/customer_detail.html index f1f7b0f..dd2bbec 100644 --- a/src/storefront/templates/storefront/customer_detail.html +++ b/src/storefront/templates/storefront/customer_detail.html @@ -63,16 +63,16 @@ - + {% for subscription in subscriptions %} - + - + {% endfor %} @@ -95,7 +95,7 @@ - + {% empty %} diff --git a/src/storefront/templates/storefront/order_detail.html b/src/storefront/templates/storefront/order_detail.html index 7881c5f..4182022 100644 --- a/src/storefront/templates/storefront/order_detail.html +++ b/src/storefront/templates/storefront/order_detail.html @@ -8,6 +8,11 @@

Order #{{order.pk}}

Placed on {{order.created_at|date:"M j, Y"}}

+ {% if order.subscription %} +
+

Subscription: {{ order.subscription_description }}


+
+ {% endif %}
Subscription #Subscription Status
{{ subscription.id }}#{{ subscription.metadata.subscription_pk }} {{ subscription.status }}manage subscription ↗manage ↗
#{{order.pk}} {{order.created_at|date:"M j, Y"}}${{order.get_total_price_after_discount}}${{order.total_amount}} See details →
@@ -71,7 +76,7 @@
- + {% if order.coupon %} diff --git a/src/storefront/views.py b/src/storefront/views.py index 46f4acf..d1f159f 100644 --- a/src/storefront/views.py +++ b/src/storefront/views.py @@ -600,57 +600,10 @@ class SubscriptionFormView(FormView): return super().form_valid(form) -class SubscriptionAddAddressView(FormView): +class SubscriptionAddAddressView(CheckoutAddressView): template_name = 'storefront/subscription/address.html' - form_class = AddressForm success_url = reverse_lazy('storefront:subscription-create') - def get_initial(self): - user = self.request.user - initial = None - if user.is_authenticated and user.default_shipping_address: - address = user.default_shipping_address - initial = { - 'full_name': address.first_name + ' ' + address.last_name, - 'email': user.email, - 'street_address_1': address.street_address_1, - 'street_address_2': address.street_address_2, - 'city': address.city, - 'state': address.state, - 'postal_code': address.postal_code - } - elif self.request.session.get('shipping_address'): - address = self.request.session.get('shipping_address') - initial = { - 'full_name': address['first_name'] + ' ' + address['last_name'], - 'email': address['email'], - 'street_address_1': address['street_address_1'], - 'street_address_2': address['street_address_2'], - 'city': address['city'], - 'state': address['state'], - 'postal_code': address['postal_code'] - } - return initial - - def form_valid(self, form): - # save address data to session - cleaned_data = form.cleaned_data - first_name, last_name = form.process_full_name( - cleaned_data.get('full_name') - ) - address = { - 'first_name': first_name, - 'last_name': last_name, - 'email': cleaned_data['email'], - 'street_address_1': cleaned_data['street_address_1'], - 'street_address_2': cleaned_data['street_address_2'], - 'city': cleaned_data['city'], - 'state': cleaned_data['state'], - 'postal_code': cleaned_data['postal_code'] - } - self.request.session['shipping_address'] = address - return super().form_valid(form) - class SubscriptionCreateView(SuccessMessageMixin, CreateView): model = Subscription
Subtotal${{order.subtotal}}${{order.subtotal_amount}}