Page 1 of 1

Paid Sale Trigger

Posted: Thu Oct 08, 2009 7:51 pm
by dalej
Is there not some way to hook into a Sale at the point where an order is complete and the credit card payment has been confirmed? I need to notify another (outside) process of the Sale status - eg. If Product X is in the order, toggle process Y; if Product A was sold, toggle process B, etc.

Is there an event raised at the point the Order Status changes? or an overload available for the code-behind?

I was looking at Order.OrderStatus.Triggers[] but that seems to be limited to email functions...

Re: Paid Sale Trigger

Posted: Fri Oct 09, 2009 3:32 am
by mazhar
You can do this stuff in CheckedOut method of ConLib/OnePageCheckout.ascx.cs method. Edit this file and then locate CheckedOut method and do something like below

Code: Select all

if (response.Success)
{
            Order order = OrderDataSource.Load(e.OrderId);
            if(order.OrderStatus.Name == "someorderstatus")
            {
                            //do your custom notification stuff here
            }
            ------------------------------------
            ------------------------------------
            ------------------------------------
}

Re: Paid Sale Trigger

Posted: Fri Oct 09, 2009 9:51 am
by dalej
Many thanks Mazhar. That indeed seem to be the obvious "hook". A couple of subsequent questions:

1. Would hooking in at this point also take into consideration gift certificates and coupons?

2. Would the same logic apply for subscription sales where the initial payment and/or first recurring payment has been paid?

3. Lets say I create an Order Status of "CompletelyPaid" with triggers of "Order Paid" and "Order Paid No Shipments". Are those 2 triggers a logical AND or OR condition to trigger the status of "CompletelyPaid"?

4. Does re-loading the order with OrderDataSource.Load automatically recalculate the OrderPaymentStatus? Or would it be wise to call order.RecalculatePaymentStatus() after the re-load but before the status check?

5. Is checking order.OrderStatus.Name == "someorderstatus" better than checking if order.PaymentStatusId == "paid"? Or for that matter, checking if order.GetBalance() <= 0 ?

Re: Paid Sale Trigger

Posted: Sat Oct 10, 2009 3:38 am
by mazhar
1. Would hooking in at this point also take into consideration gift certificates and coupons?
You can iterate over the order items and can access coupons or gift certificate like

Code: Select all

foreach(OrderItem orderItem in order.Items)
{
if(orderItem.OrderItemType == OrderItemType.Coupon)
//Coupon processing code here
else
if(orderItem.OrderItemType == OrderItemType.GiftCertificate)
//Gift Certificate processing code here
}
2. Would the same logic apply for subscription sales where the initial payment and/or first recurring payment has been paid?
Yes
3. Lets say I create an Order Status of "CompletelyPaid" with triggers of "Order Paid" and "Order Paid No Shipments". Are those 2 triggers a logical AND or OR condition to trigger the status of "CompletelyPaid"?
You can take it like logical or.
4. Does re-loading the order with OrderDataSource.Load automatically recalculate the OrderPaymentStatus? Or would it be wise to call order.RecalculatePaymentStatus() after the re-load but before the status check?
No need to call recalculate on order again. Just load by using OrderDataSource.Load(orderId,false) it will order object without using cached one.
5. Is checking order.OrderStatus.Name == "someorderstatus" better than checking if order.PaymentStatusId == "paid"? Or for that matter, checking if order.GetBalance() <= 0 ?
Its up to you, you can check it depending upon payment status like

Code: Select all

if(order.PaymentStatus == PaymentStatus.Paid)
{

}

Re: Paid Sale Trigger

Posted: Fri Oct 16, 2009 12:56 pm
by dalej
I think that should be:

Code: Select all

if(order.PaymentStatus == OrderPaymentStatus.Paid)