Get the individual identifier of the option in the kit

I work with a GIANT list of related items, but I only want to display some of them as options based on user input criteria. It was simple enough by simply setting the if statement line by line:

$returnedproducts = array(21,50,78,23); // THESE ARE PRODUCT IDS. if ($_product->getTypeId() == 'bundle'){ $selectionCollection = $_product->getTypeInstance(true)->getSelectionsCollection( $_product->getTypeInstance(true)->getOptionsIds($_product), $_product ); foreach($selectionCollection as $option) { if(array_search($option['product_id'], $returnedproducts) !== FALSE){ // ADDED THIS TO FILTER echo '<li>' . $option->option_id . '</li>'; } } } 

The problem is that it simply sucks tons of resources due to the size of the list and several other factors. I would like to find a way to find and display only certain parameter identifiers without having to sift through the entire list (it is possible to add WHERE product_id = XXXX to the query that receives the parameter identifiers). However, I cannot find a solution to search for individual package parameters. Can someone help me achieve this?

+4
source share
1 answer

I will probably catch some reaction to this, but I found that when you reach the top of the huge collections in Magento, you can do one of two things.

You can...

  • Throw money on your hosting solution for more ram / processors / etc
  • Use direct sql reads

Using sql reads is not particularly dangerous, since you are not going to try to translate something into a highly managed database using code that has not been fully tested. Your chances are pretty subtle. Yes, there is a chance that everything may go wrong, but you need to weigh the costs / benefits of using a trick like this, which is great for your particular case. It still uses the Magento sql interface, not the user interface.

Modify the following code to list entities or whatever you want to find and use the THAT result to create the collection.

 // Just in case ---$mysqli = Mage::getSingleton('core/resource')->getConnection('core_write'); $mysqlr = Mage::getSingleton('core/resource')->getConnection('core_read'); $sql = "select * from some_entity_table where some_column = 'somevars'"; $results = $mysqlr->fetchAll($sql); echo "<PRE>"; foreach ($results as $res) { var_dump($res); } 
-1
source

All Articles