0

This is the event that I used: sales_order_save_before and this is my function:

  public function test(Varien_Event_Observer $observer)
    {
        $order = $observer->getEvent()->getOrder;
        var_dump($order->getData('created_at'));  // this is null 
        var_dump($order->getIncrementId());  // this is good, i got a value 
        var_dump($observer->getEvent()->getData('created_at')); // this is  null
        exit();
    }

When I press the place order button an ajax request is made: /checkout/onepage/saveOrder/form_key/eKIOUrQBzrvNCYdY/

If I do a var dump of order->getData(), it simply takes too long to display the result in the firebug . I waited more then 5 minutes so I stopped.

My question is how do i get the created_at value from the order ?

Thx

0

You are using this on sales_order_save_before. at this time order is not yet saved but before that the Increment Id was generated thats why you are getting that

If you use sales_order_save_after event then you will get all the data of order. And if you want to use this at the time of place order then you have to use sales_order_place_after event.

0

You can get order create date like this.

echo $order->getCreatedAtDate();
0

Magento, set sales order, invoice, shipment, credit memo created_at after before_save and before after_save event.

Basically, all sales related object order, shipment, credit memo, invoice created_at field value set whenever it prepareDataForSave() Prepare data for save at database.

If you see that Magento sales object's resource Db Abstract class Mage_Sales_Model_Resource_Abstract, then you can understand that.

We already now that prepareDataForSave() fire when after before_save and before after_save event. You can get a clear view at resource db abstract class Mage_Core_Model_Resource_Db_Abstract at function save(),

 public function save(Mage_Core_Model_Abstract $object)
    {
    .....   

        $this->_beforeSave($object);
        $this->_checkUnique($object);
        if (!is_null($object->getId()) && (!$this->_useIsObjectNew || !$object->isObjectNew())) {
            $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId());
            /**
             * Not auto increment primary key support
             */
            if ($this->_isPkAutoIncrement) {

                $data = $this->_prepareDataForSave($object);
                unset($data[$this->getIdFieldName()]);
                $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
            } else {
                $select = $this->_getWriteAdapter()->select()
                    ->from($this->getMainTable(), array($this->getIdFieldName()))
                    ->where($condition);
                if ($this->_getWriteAdapter()->fetchOne($select) !== false) {

                    $data = $this->_prepareDataForSave($object);

                    unset($data[$this->getIdFieldName()]);
                    if (!empty($data)) {
                        $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
                    }
                } else {
                    $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object));
                }
            }
        } else {
            $bind = $this->_prepareDataForSave($object);
            if ($this->_isPkAutoIncrement) {
                unset($bind[$this->getIdFieldName()]);
            }
            $this->_getWriteAdapter()->insert($this->getMainTable(), $bind);

            $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable()));

            if ($this->_useIsObjectNew) {
                $object->isObjectNew(false);
            }
        }

    ......
        $this->_afterSave($object);

        return $this;
    }

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.