Question

Trying to change the default state/status for orders that have only giftcard products.

Tried to find an event I can "observe" to achieve that but no luck. Also tried to change the setting in System > Configuration > Catalogue > Downloadable Product Options > Order Status but the same, no luck.

Anyone can point me in the right direction please? Any help is kindly appreciated.

Thanks

LATER EDIT

My bad, should've mentioned from the start I tried all the obvious, sales_order_place_after and related events, they don't work.

Was it helpful?

Solution 2

Since I got nowhere with events and after chatting with Vinai Kopp a few minutes decided that a good ol' rewrite is needed, since orders containing virtual products are a bit different than "normal" ones (they don't need shipments to be "completed").

OTHER TIPS

Hi you can use sales_order_place_after event.you need to define below code in your module config.xml.

 <global>
     <events>
        <sales_order_place_after>
            <observers>
                <OBSERVER_NAME>
                    <class>MODULE_FRONTNAME/NAME_OF_FILE_IN_MODEL_FOLDER</class>
                    <method>FUNCTION_NAME_FROM_ABOVE_CLASS</method>
                </OBSERVER_NAME>
            </observers>
        </sales_order_place_after>
     </events>
 </global>

If you need to define file under following path: app/code/YOUR_CODEPOOL/NAMESPACE/YOUR_MODULE/Model/NAME_OF_FILE_IN_MODEL_FOLDER.php Like Observer.php

In above file need to create function in observer.php with name which define in tag of config.xml:

<?php
    public function sales_order_afterPlace($observer)
    {
      $order = $observer->getEvent()->getOrder();
      $order_items = $order->getAllVisibleItems();
      foreach ($order_items as $_item)
      {
          if($_item->getProductType()=='giftcard')
          {
             $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
             $order->save();
             break;
          }
      }
    }
?>

Following is a list a possible states:

Mage_Sales_Model_Order::STATE_NEW

Mage_Sales_Model_Order::STATE_PENDING_PAYMENT

Mage_Sales_Model_Order::STATE_PROCESSING

Mage_Sales_Model_Order::STATE_COMPLETE

Mage_Sales_Model_Order::STATE_CLOSED

Mage_Sales_Model_Order::STATE_CANCELED

Mage_Sales_Model_Order::STATE_HOLDED

I hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top