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);
$stockItem->save();
}
}
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?