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