Advertisement
tjromano

Lower than 4000

Jan 12th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. /* file to get sku, pixel_height, pixel_width under 4000 */
  4.  
  5. // make sure we don't time out
  6. set_time_limit(0); 
  7.  
  8. // include Mage
  9. require_once 'app/Mage.php';
  10. Mage::app('default');
  11.  
  12. $pixel_height = 4000;
  13. $pixel_width = 4000;
  14.  
  15. $dt = time();
  16. //$filename = $dt."_pix_size_export.csv";
  17. $filename = "pix_size_export.csv";
  18. $headers = array('sku', 'pixel_height', 'pixel_width');
  19.  
  20. // open file for writing
  21. $fp = fopen($filename, 'w');
  22.  
  23. fputcsv($fp, $headers); // add headers to file
  24.  
  25. echo "<p>Getting products with pix_height <= ".$pixel_height." and pix_width <= ".$pixel_width."</p>";
  26.  
  27. $products = Mage::getModel('catalog/product')
  28.     ->getCollection()
  29.     ->addAttributeToFilter('status', 1) //enabled
  30.     ->addAttributeToFilter(array(
  31.         array(
  32.             'attribute' => 'pixel_height',
  33.             'gteq' => $pixel_height
  34.         ),
  35.         array(
  36.             'attribute' => 'pixel_width',
  37.             'gteq' => $pixel_width
  38.         )
  39.     ))
  40.     //->addAttributeToFilter('pixel_height', array('gteq' => $pixel_height))
  41.     //->addAttributeToFilter('pixel_width', array('gteq' => $pixel_width))
  42.     ->addAttributeToSelect('sku')
  43.     ->addAttributeToSelect('pixel_height')
  44.     ->addAttributeToSelect('pixel_width');
  45.     //echo $products->getSelect();
  46.     //exit;
  47.    
  48. echo "<p>Total Products Found: ".$products->count()."</p>";
  49.  
  50. echo "<pre>";
  51. foreach($products as $p) {
  52.     $data = array(
  53.         'sku' => $p->getSku(),
  54.         'pixel_height' => $p->getPixelHeight(),
  55.         'pixel_width' => $p->getPixelWidth()
  56.     );
  57.     //print_r($data);
  58.     fputcsv($fp, $data);
  59. }
  60. echo "</pre>";
  61. echo "<p>File created: <a href='".$filename."'>".$filename."</a></p>";
  62. fclose($fp);
  63.  
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement