I am working in customized site that site have used the product model load within loop multiple times.

$product = Mage::getModel('catalog/product')->load($productId);

Any Quick Fix that I can use with override the load method and keep minimum php resources and make it better for more concurrent users.

  • Please provide that code – Gopal Patel Nov 20 '16 at 6:21
  • A solution cannot be provided from just one line of code. Please provide the entire block of code. – ProxiBlue Nov 20 '16 at 6:53
  • And there really is no 'one solution fits all' if this is done in multiple instances. Each will need to be analyzed, figure out what its up to, and be corrected, within the scope of each routine. If they are all the same, identical code blocks, you got bigger problems.... – ProxiBlue Nov 20 '16 at 6:57

In general the colleagues are right. But in this specific example you can try to use directly collection. Instead of:

foreach ($productIds as $productId) {
    $product = Mage::getModel('catalog/product')->load($productId);

use something like this:

$products = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $productIds));
foreach ($products as $product) {
    //do something

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.