Page 1 of 1

Gift Certificate Activation

Posted: Wed Dec 17, 2008 1:12 pm
by page8worker
Is it possible to have a gift certificate automatically activated if/when the payment method is approved, or the order is marked as paid?

Thanks,

Re: Gift Certificate Activation

Posted: Thu Dec 18, 2008 5:27 am
by sohaib
This has been fixed in our development (and will be available in 7.2) ... but a workaround for now could be to write some custom code in 'CheckedOut' event handler on 'One Page Checkout' page.

Re: Gift Certificate Activation

Posted: Thu Dec 18, 2008 6:08 am
by mazhar
Edit your ConLib/OnePageCheckout.ascx.cs file and change the Checkedout method to look like as below

Code: Select all

 void CheckedOut(object sender, CheckedOutEventArgs e)
    {
..............................................................................
..............................................................................
..............................................................................

 //Activate GiftCertificate 
        Order order = OrderDataSource.Load(e.OrderId, false);
        if (order != null)
        {
            if (order.OrderStatus.Name == "Completed")
            {
                foreach (OrderItem orderItem in order.Items)
                {
                    if (orderItem.OrderItemType == OrderItemType.Product)
                    {
                        if (orderItem.Product.IsGiftCertificate)
                        {
                            GiftCertificateCollection giftCertificates = GiftCertificateDataSource.LoadForOrderItem(orderItem.OrderItemId);

                            if (giftCertificates.Count > 0)
                            {
                                IGiftCertKeyProvider provider = new DefaultGiftCertKeyProvider();
                                foreach (GiftCertificate giftCertificate in giftCertificates)
                                {   
                                    giftCertificate.SerialNumber = provider.GenerateGiftCertificateKey();
                                    giftCertificate.AddActivatedTransaction();
                                    giftCertificate.Save();
                                }
                            }
                        }
                    }
                }
            }
        }
}

Re: Gift Certificate Activation

Posted: Thu Dec 18, 2008 7:39 am
by heinscott
Ah, nice! Thanks Mazhar... This answers a question I had about where to adjust an Inventory History table I was working on. Didn't know that the order # was available before the reciept page.
Thanks!

Scott

Re: Gift Certificate Activation

Posted: Thu Dec 18, 2008 11:57 am
by AbleMods
No way - the stored order is available in onepagecheckout??

News to me too - all sorts of new doors open up :twisted:

Re: Gift Certificate Activation

Posted: Wed Jan 14, 2009 10:56 pm
by page8worker
Sorry for the late response; I've been out of town for the holidays. I just wanted to say thank you for your help with the matter, and I'll give it a try as soon as I get a chance.

Thanks again,