We have an API that we check with on Catalog/Product/View page load. This API returns the current inventory quantities for all the simple products associated with the configured product being loaded. Then we save these quantities to the database.

            // update the products which were returned in the response
    foreach ($this->_stockByUpcId as $upc => $available) {
        $product = Mage::getModel('catalog/product')->loadByAttribute('upc_identifier', $upc);
        if ($product && $product->getId() && $product->getUpcIdentifier() == $upc) {
            $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
            $stockItem->setData('qty', $available);
            $stockItem->setData('is_in_stock', $available > 0);

The problem is this is taking way too much time, on the order of 10-40 seconds. Any ideas or ways to improve the speed of this process?

1 Answer 1


There are multiple issues with such an approach:

  1. You should not save any data on product view. Imagine 100 concurrent customers saving your products on the frontend. It will only make it worse with the growth of the website.

  2. Doing API calls for every product is too expensive. It will only get worse with the growth of your catalog.


  1. If ERP allows using document based exchange (e.g. a simple CSV file) you can update within second thousands of simple product stock statuses.

  2. Doing delta updates would even allow dealing with almost real-time stock information, there might be data lag of 2 minutes, but that is neglectable on product view.

  3. If realtime level stock accuracy is a MUST, then you can perform a final inventory check over API right before the order is placed, and raise an exception if you cannot sell the item, then Magento will revert the order transaction before the payment is done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.