1

I have observer the stock item when order placed:

<global>
    <events>
                    ...
        <cataloginventory_stock_item_save_commit_after>
            <observers>
                <mymodule_stock_item_save_after>
                    <class>mymodule/observer_stockItem</class>
                    <method>afterSaveStockItem</method>
                </mymodule_stock_item_save_after>
            </observers>
        </cataloginventory_stock_item_save_commit_after>
    </events>
</global>

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. 1.13.0.2)?

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.

6
  • 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
2

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')
                    ->loadByProduct($orderItem->getProductId());
                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.