I have observer the stock item when order placed:


The code handle the event:

public function afterSaveStockItem($observer) {
    $productId = $observer->getEvent()->getItem()->getProductId();
    Mage::log($productId, null, "stockItemOrder.log");

I try place an order with two products, but the log out only one product id.

what is the problem? Could I have a bug in my magento install(ver.

Update: After some check the stock event is not fired when order is created. So I marked my question to CLOSED, many thanks to everyone.

  • Now it doesn't run that event when order placed at all.
    – Lan Nguyen
    May 9 '14 at 3:02
  • 1
    the config.xml you have posted seems to have an error in it, the closing cataloginventory_stock_item_save_commit_after appears to be mymodule_stock_item_save_commit_after May 17 '14 at 6:59
  • Was that the only issue you where having? May 17 '14 at 11:29
  • No the issue is the cataloginventory_stock_item_save_commit_after event not fired when order created. I closed this question, thanks for your support.
    – Lan Nguyen
    May 17 '14 at 11:33
  • And you have the the shop working with stock status or is that disabled? May 17 '14 at 11:39

I use a module that tracks stock movements, for all sales it uses the checkout_submit_all_after event.

Inside the Observer it uses this function:

public function checkoutAllSubmitAfter($observer)
    if ($observer->getEvent()->hasOrders()) {
        $orders = $observer->getEvent()->getOrders();
    } else {
        $orders = array($observer->getEvent()->getOrder());
    $stockItems = array();
    foreach ($orders as $order) {
        foreach ($order->getAllItems() as $orderItem) {
            if ($orderItem->getQtyOrdered()) {
                $stockItem = Mage::getModel('cataloginventory/stock_item')
                if (!isset($stockItems[$stockItem->getId()])) {
                    $stockItems[$stockItem->getId()] = array(
                        'item'   => $stockItem,
                        'orders' => array($order->getIncrementId()),
                } else {
                    $stockItems[$stockItem->getId()]['orders'][] = $order->getIncrementId();

Modify this code and give it a whirl :)

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.