cancel
Showing results for 
Search instead for 
Did you mean: 

Insert constant quantity of product on order saved or updated

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();
      }
  }

 

1 REPLY 1

Re: Insert constant quantity of product on order saved or updated

can you please specify some more detail for your question.

Was my answer helpful? You can Click Kudos/Accept As Solution.
200+ professional extensions for M1 & M2 with free lifetime updates!