Loading multiple objects from a database

I have several thousand dynamic identifiers .. lets talk products. Now I want to download these products without sending more than a thousand requests to db. So this is not a solution:

$products = array(); foreach( $ids as $id ){ $products[] = Mage::getModel('catalog/product')->load($id); } 

But since I need complete products, this is also not a solution:

 $products = Mage::getModel('catalog/product')->getCollection(); $products->addFieldToFilter( 'entity_id', array( 'in', $ids ) ); 

So, do I really need to load each individual product, which will probably cause more than 3000 requests and take a couple of minutes?

+4
source share
1 answer

You should do something like:

 $products = Mage::getModel('catalog/product')->getCollection(); foreach (<product attributes> as <attribute code>) { $products->addAttributeToSelect(<attribute code>); } 

and after that do

 $products->addFieldToFilter( 'entity_id', array( 'in', $ids ) ); 
+2
source

Source: https://habr.com/ru/post/1393960/


All Articles