Paid Sale Trigger

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
dalej
Ensign (ENS)
Ensign (ENS)
Posts: 7
Joined: Thu Jul 23, 2009 4:21 pm

Paid Sale Trigger

Post by dalej » Thu Oct 08, 2009 7:51 pm

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...

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Paid Sale Trigger

Post by mazhar » Fri Oct 09, 2009 3:32 am

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
            }
            ------------------------------------
            ------------------------------------
            ------------------------------------
}

dalej
Ensign (ENS)
Ensign (ENS)
Posts: 7
Joined: Thu Jul 23, 2009 4:21 pm

Re: Paid Sale Trigger

Post by dalej » Fri Oct 09, 2009 9:51 am

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 ?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Paid Sale Trigger

Post by mazhar » Sat Oct 10, 2009 3:38 am

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)
{

}

dalej
Ensign (ENS)
Ensign (ENS)
Posts: 7
Joined: Thu Jul 23, 2009 4:21 pm

Re: Paid Sale Trigger

Post by dalej » Fri Oct 16, 2009 12:56 pm

I think that should be:

Code: Select all

if(order.PaymentStatus == OrderPaymentStatus.Paid)

Post Reply