Skip to content

Instantly share code, notes, and snippets.

@philwinkle
Last active December 22, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philwinkle/6530362 to your computer and use it in GitHub Desktop.
Save philwinkle/6530362 to your computer and use it in GitHub Desktop.
Load product collection by IDs
<?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
}
<?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