Magento: observer state for state completed

At Magento, I am developing a commission module that I need to pay with my agents when sales are completed, and not when the order is placed.

Ideally, I would like to capture it when the state of order becomes "complete", but I did not find an observer for this?

I could add this to the shipping supervisor, but the order may have several batches and therefore is not correct.

Alternatively, I could always run the cron job to calculate the order in the last hour, but again it doesn't seem to be correct.

Any suggestions on how to do this correctly.

+6
source share
2 answers

Use the observer "sales_order_save_commit_after" or "sales_order_invoice_pay", then you can get the order status and depending on what 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 need to verify that you are not performing the calculation twice, because this method runs every time an order is saved.

+23
source

** magento order complete and cancels quantity changes when increasing and decreasing per database observer ** Zero / SalesOderafter / config.xml

  <config> <modules> <Zero_SalesOrderafter> <version>0.1.0</version> </Zero_SalesOrderafter> </modules> <global> <events> <sales_order_save_after> <observers> <ordercancel> <type>singleton</type> <class>Zero_SalesOrderafter_Model_Observer</class> <method>canCancelOrder</method> </ordercancel> </observers> </sales_order_save_after> </events> </global> </config> path:Zero/SalesOrderafter/Observer.php class Wli_SalesOrderafter_Model_Observer { public function canCancelOrder( Varien_Event_Observer $observer ) { $data = $observer->getEvent()->getOrder(); if($data->getId()) { $ProdustIds=array(); foreach ($data->getAllVisibleItems() as $item) { $ProdustIds= $item->getProductId(); } } $qty = $data->getData('total_qty_ordered'); $order_status = $data->getStatus(); $incrementId = $data->getData('increment_id'); } } ?> 
0
source

Source: https://habr.com/ru/post/900271/


All Articles