Last active
December 22, 2015 20:59
-
-
Save philwinkle/6530362 to your computer and use it in GitHub Desktop.
Load product collection by IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ids = array(1,2,3,4); | |
//DON'T DO THIS | |
foreach($ids as $id){ | |
Mage::getModel('catalog/product')->load($id); | |
} | |
//Rather do this | |
$collection = Mage::getModel('catalog/product') | |
->getCollection() | |
//->addAttributeToSelect('*') // if you want to load all attrs, use this | |
->addAttributeToFilter('entity_id', array('in' => $ids)); | |
foreach($collection as $product){ | |
//do stuff | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('app/Mage.php'); | |
Mage::app(); | |
$urls = array(); | |
for($i;$i<7000;$i++){ | |
//stuffing an array with 7000 "urls" | |
$urls[] = "http://www.mysite.com/media/catalog/product/cache/0/small_image/135x/images/catalog/product/placeholder/small_image.jpg"; | |
} | |
$conn = Mage::getSingleton('core/resource')->getConnection('core_write'); | |
$sql = sprintf("INSERT INTO mytable (url) VALUES ('%s');",join("'),('",$urls)); | |
$conn->query($sql); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment