cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with entering a fixed amount of products on the saved or updated order

Highlighted

Problem with entering a fixed amount of products on the saved or updated order

Insert constant quantity of product on order saved or updated

Hello, I want to insert a constant quantity of a product when and order is saved or created.

I'm using the event 'sales_order_save_after'.

The event is triggered twice and the quantity is not modified, it is only decremented.  How to fix that?

  public function save_product_frontend($observer = null) { 
       $event = $observer->getEvent();
       $order = $event->getOrder();
       $items = $order->getAllItems();
       foreach ($items as $item) {
          $product = Mage::getModel("catalog/product")->load( $item->getProductId() );
          $stockitem = Mage::getModel('cataloginventory/stock_item')->loadByProduct( $product );
          $stockitem->setQty( 100 );
          $stockitem->save();
      }
  }