0
votes

I have working on magento 1.6.1.0 version. I have not found any event to call after shipping generate or after order status completed. Then i call our module observer when order status is completed.

After order status complete, i want to update a customer attribute value.

please give me answer of this problem.

I have search and do various things but they are not useful.

1
Which events have you tried which didn't work?benmarks
@benmarks I have not find any event which is run after order status completed. I have try "sales_order_payment_pay" but this is trigerred after payment receive not order completed.Kapil Gupta

1 Answers

0
votes

The first place to start would be the sales_order_save_after event. This certainly will work, but will be called any time the order is updated and saved. Therefore the logic must consider when the order is newly created & complete straightaway, or when the order is marked as complete later on (the latter being the most common). You may need to adjust logic and acceptable end-state values for orders based on cancellations, multiple orders, etc.

/**
 * Update customer attribute when order is completed.
 * 
 * Need to catch two conditions:
 * 1) Order is new AND `status` = complete
 * 2) Order exists but `status` is changed to complete
 *
 * @param $obs Varien_Event_Observer
 */
public function adjustCustomerAfterComplete($obs)
{
    /* @var $order Mage_Sales_Model_Order */
    $order = $obs->getOrder();

    if ($order->getStatus() === $order::STATE_COMPLETE
        && $order->getOrigData('status' !== $order::STATE_COMPLETE))
    {
        Mage::getModel('customer/customer')
                ->load($order->getCustomerId())
                ->setCustomAttr('new val') //custom attr code
                ->save();

        //Another approach if you don't need events, etc.:
        /*
        $obj = new Varien_Object(
            array(
                 'entity_id'=>$order->getCustomerId(),
                 'custom_attr'=>'new val'
            )
        );

        Mage::getResourceModel('customer/customer')
                 ->saveAttribute($obj,'custom_attr');
        */
    }
}