# Path: simplestore/settings/base.py
# EMAIL_ADMIN = 'test@martinstastny.cz'
# 
# Path: simplestore/checkout/models/order.py
# class Order(models.Model):
#     uuid = models.UUIDField(default=uuid4, unique=True, editable=False)
#     slug = models.UUIDField(default=uuid4, unique=True, editable=False)
#     cart = models.ForeignKey(Cart, on_delete=models.DO_NOTHING)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
#     full_name = models.CharField(max_length=120)
#     email = models.EmailField()
#     phone = models.CharField(max_length=120, null=True, blank=True)
#     status = models.CharField(choices=ORDER_STATUS_CHOICES, max_length=120, default='Created')
#     created_at = models.DateTimeField(auto_now=True)
#     updated_at = models.DateTimeField(auto_now_add=True)
#     shipping_address = models.ForeignKey(Address, on_delete=models.DO_NOTHING, related_name='shipping_address',
#         null=True)
# 
#     class Meta:
#         ordering = ['-created_at']
# 
#     def get_short_uuid(self):
#         uuid = str(self.uuid).split('-')
#         return "{0}-{1}".format(uuid[0], uuid[1])
# 
#     def get_cart_items(self):
#         return self.cart.items.all()
# 
#     def get_absolute_url(self):
#         return reverse('checkout:order-confirmation', kwargs={'slug': str(self.slug)})
# 
#     def create_order_items(self):
#         cart_items = self.cart.items.all()
#         for item in cart_items:
#             OrderItem.objects.create(order=self, product=item.product, price=item.product.price,
#                 quantity=item.quantity)
# 
#     def get_serialized_items(self):
#         order_items = []
#         for item in self.cart.items.all():
#             data = {
#                 'name': item.product.name,
#                 'sku': item.product.sku,
#                 'quantity': item.quantity,
#                 'price': item.product.price,
#                 'total_price': item.total_price,
#             }
#             order_items.append(data)
#         return order_items
# 
#     def get_serialized_data(self):
#         return {
#             'short_uuid': self.get_short_uuid(),
#             'email': self.email,
#             'full_name': self.full_name,
#             'phone': self.phone,
#             'status': self.status,
#             'shipping_address': self.shipping_address,
#             'order_items': self.get_serialized_items(),
#         }
# 
#     def __str__(self):
#         return 'Order num. {0}'.format(self.id)


from django.core.mail import EmailMessage
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.template import Context
from django.template.loader import get_template
from simplestore.settings.base import EMAIL_ADMIN
from .models.order import Order



@receiver(post_save, sender=Order)
def send_order_email_confirmation(sender, instance, **kwargs):
    """
    Send email to customer with order details.
    """
    order = instance
    message = get_template("emails/order_conf.html").render(Context({
        'order': order.get_serialized_data()
    }))
    mail = EmailMessage(
        subject="Order confirmation",
        body=message,
        from_email=EMAIL_ADMIN,
        to=[order.email],

# Path: simplestore/settings/base.py
# EMAIL_ADMIN = 'test@martinstastny.cz'
# 
# Path: simplestore/checkout/models/order.py
# class Order(models.Model):
#     uuid = models.UUIDField(default=uuid4, unique=True, editable=False)
#     slug = models.UUIDField(default=uuid4, unique=True, editable=False)
#     cart = models.ForeignKey(Cart, on_delete=models.DO_NOTHING)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
#     full_name = models.CharField(max_length=120)
#     email = models.EmailField()
#     phone = models.CharField(max_length=120, null=True, blank=True)
#     status = models.CharField(choices=ORDER_STATUS_CHOICES, max_length=120, default='Created')
#     created_at = models.DateTimeField(auto_now=True)
#     updated_at = models.DateTimeField(auto_now_add=True)
#     shipping_address = models.ForeignKey(Address, on_delete=models.DO_NOTHING, related_name='shipping_address',
#         null=True)
# 
#     class Meta:
#         ordering = ['-created_at']
# 
#     def get_short_uuid(self):
#         uuid = str(self.uuid).split('-')
#         return "{0}-{1}".format(uuid[0], uuid[1])
# 
#     def get_cart_items(self):
#         return self.cart.items.all()
# 
#     def get_absolute_url(self):
#         return reverse('checkout:order-confirmation', kwargs={'slug': str(self.slug)})
# 
#     def create_order_items(self):
#         cart_items = self.cart.items.all()
#         for item in cart_items:
#             OrderItem.objects.create(order=self, product=item.product, price=item.product.price,
#                 quantity=item.quantity)
# 
#     def get_serialized_items(self):
#         order_items = []
#         for item in self.cart.items.all():
#             data = {
#                 'name': item.product.name,
#                 'sku': item.product.sku,
#                 'quantity': item.quantity,
#                 'price': item.product.price,
#                 'total_price': item.total_price,
#             }
#             order_items.append(data)
#         return order_items
# 
#     def get_serialized_data(self):
#         return {
#             'short_uuid': self.get_short_uuid(),
#             'email': self.email,
#             'full_name': self.full_name,
#             'phone': self.phone,
#             'status': self.status,
#             'shipping_address': self.shipping_address,
#             'order_items': self.get_serialized_items(),
#         }
# 
#     def __str__(self):
#         return 'Order num. {0}'.format(self.id)


# Path: simplestore/checkout/signals.py
from django.core.mail import EmailMessage
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.template import Context
from django.template.loader import get_template
from simplestore.settings.base import EMAIL_ADMIN
from .models.order import Order




@receiver(post_save, sender=Order)
def send_order_email_confirmation(sender, instance, **kwargs):
    """
    Send email to customer with order details.
    """
    order = instance
    message = get_template("emails/order_conf.html").render(Context({
        'order': order.get_serialized_data()
    }))
    mail = EmailMessage(
        subject="Order confirmation",
        body=message,
        from_email=EMAIL_ADMIN,
        to=[order.email],

        reply_to=[EMAIL_ADMIN],