0

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.

0

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.

  • yeah, forgot to mention that's the first thing I tried, to listen to sales_order_place_after - doesn't work. – George Schiopu Jun 17 '16 at 14:35
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.