Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Created September 11, 2014 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molotovbliss/cb2e3fc92684307d7e5b to your computer and use it in GitHub Desktop.
Save molotovbliss/cb2e3fc92684307d7e5b to your computer and use it in GitHub Desktop.
Memory limit proof generate CSV of missing product images
<?php
// generate a CSV of id,sku of products with missing images to var/missingimages.csv
// core/resource_iterator used to prevent memory max limits issues
// original source: https://stackoverflow.com/questions/3565377/how-can-i-find-all-products-without-images-in-magento
require_once('app/Mage.php');
umask(0);
ini_set('display_errors', 1);
Mage::setIsDeveloperMode(true);
Mage::app();
set_time_limit(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
function productCallback($args)
{
$product = Mage::getModel('catalog/product');
$product->setData($args['row']);
echo $product->getSku() . "\n<br />";
$product_data = array();
$product_data['id'] = $product->getEntityId();
$product_data['sku'] = $product->getSku();
$GLOBALS['csvdata'][] = $product_data;
}
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('sku')
->addAttributeToFilter(array(
array (
'attribute' => 'image',
'like' => 'no_selection'
),
array (
'attribute' => 'image', // null fields
'null' => true
),
array (
'attribute' => 'image', // empty, but not null
'eq' => ''
),
array (
'attribute' => 'image', // check for information that doesn't conform to Magento's formatting
'nlike' => '%/%/%'
),
));
Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(), array('productCallback'), array('arg1' => '===='));
$file = 'var/missingimages.csv';
$csv = new Varien_File_Csv();
$csv->setDelimiter(',');
$csv->setEnclosure('"');
$csv->saveData($file, $csvdata);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment