0

I add a custom attribute from my module to sales order like this:

$attribute  = array(
    'type'          => 'int',
    'backend_type'  => 'int',
    'is_user_defined' => true,
    'label'         => 'Admin Id',
    'visible'       => false,
    'required'      => false,
    'user_defined'  => false,
    'searchable'    => true,
    'filterable'    => true,
    'comparable'    => true,
    'default'       => NULL
);
$installer->addAttribute('order', 'admin_id', $attribute);
$installer->addAttribute('quote', 'admin_id', $attribute);

and then I want to set the custom attribute data after I place an order using observer like this:

etc/config.xml

<global>
    <events> 
        <sales_order_save_after>
            <observers>
                <vendor_module>
                    <type>singleton</type>
                    <class>Vendor_Module_Model_Observer</class>
                    <method>orderPlace</method>
                </vendor_module>
            </observers>
        </sales_order_save_after>
    </events>
</global>

Model/Observer.php

class Vendor_Module_Model_Observer
{
   public function orderPlace($event)
   {
     $order = $event->getOrder();
     if($this->isAdmin()){
       $adminId = Mage::getSingleton('admin/session')->getUser()->getUserId();
       if($adminId){
         $orderModel = Mage::getModel('sales/order')->load($order->getId());

         $orderModel->addData(array('admin_id'=>$adminId));
         $orderModel->save(); 
       }
     }
     return $this;
   }

   private function isAdmin()
   {
      if(Mage::app()->getStore()->isAdmin())
      {
          return true;
      }

      if(Mage::getDesign()->getArea() == 'adminhtml')
      {
          return true;
      }

      return false;
   }
}

but I always got an error like this:

Allowed memory size of 10485760 bytes exhausted (tried to allocate 20480 bytes) in Unknown on line 0

or this:

Maximum execution time of 30 seconds exceeded in /var/www/vitamin/lib/Zend/Db/Adapter/Pdo/Abstract.php on line 298

0

try to increase this values on php setting

ini_set('memory_limit', '512M');
ini_set('max_execution_time', 300); //300 seconds

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.