No Email is sent when purchasing a gift certificate.

Issue #1209 resolved
Benoit Clennett-Sirois created an issue

When purchasing a gift certificate, the user is prompted to enter the recipient email address and a message, which leads the user to think an email will be sent. However, it seems that no email is sent, and the gift certificate code is never given to anyone.

I have resolved this in my own project by creating a "listener" and is initiated from models.py, containing the following code:

Note: This is not a fix-all solution. This solution is a workaround made specifically for my project's needs.

{{{

from satchmo_store.shop.signals import order_success
from django.utils.translation import ugettext as _
from satchmo_store.mail import send_store_mail
from payment.modules.giftcertificate.models import GiftCertificate

def send_gift_certificate_by_email(gc):
ctx = {
'message': gc.message,
'addressee': gc.recipient_email,
'code': gc.code,
}
subject = _('Your Gift Certificate')

send_store_mail(
    subject,
    ctx,
    template='giftcertificate/email.html',
    recipients_list=[gc.purchased_by.email,],
    fail_silently=True,
    )
return

def gift_certificate_processor(order):
gcs = GiftCertificate.objects.filter(order=order)
for gc in gcs:
gc.valid=True
gc.save()
send_gift_certificate_by_email(gc)
return

def order_success_handler(sender, order, args, *kwargs):
# If for some reason an order completes without any orderitem,
# skips any kind of check.
if not order.orderitem_set.all():
return

# If a gift certificate is in the order, setting order to "Shipped",
# which ends up calling the pre-auth complete method in the payment
# system.
gc_in_orderitems = len(filter(lambda x: 'GiftCertificateProduct' in x.product.get_subtypes(), order.orderitem_set.all()))
if gc_in_orderitems:
    order.add_status('Shipped')
    gift_certificate_processor(order)
return

def start_listeners():
order_success.connect(order_success_handler)
}}}

Comments (3)

  1. Log in to comment