On Magento, I am developing a commission module which I need to pay my agents when the sales is completed and not when the order is placed.
Ideally I would want to capture it when the order state turns into 'complete' but I have not found an observer to do this ?
I could add this to the shipment observer but a order can have multiple shipment and hence not right.
Alternatively I could always fire a cron job to calculate the order for last hour but again does not seem the right way.
Any suggestions on what is the right way to do this.
Use the observer "sales_order_save_commit_after" or "sales_order_invoice_pay" then you can get the order status and depending on the status you do what you want. Here is an example:
// for event sales_order_save_commit_after
public function commissionCalculationOnComplete($observer)
{
$order = $observer->getOrder();
if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
// do your order complete stuff
}
}
or
// Event sales_order_invoice_pay
public function triggerProvisionCalculation ($observer)
{
$invoice = $observer->getEvent()->getInvoice();
switch ($invoice->getState()) {
case Mage_Sales_Model_Order_Invoice::STATE_PAID :
//do your stuff
break;
}
return $this;
}
You will have to check that you don't do the calculation twice, because this method is triggered each time an order is saved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With