update Has Image Simple Product Visibility

require_once 'abstract.php';

/**
 * Magento Compiler Shell Script
 *
 * @category    Mage
 * @package     Mage_Shell
 * @author      Magento Core Team <[email protected]>
 */
class Mage_Shell_UpdateHasImageSimpleProductVisibility extends Mage_Shell_Abstract
{


    /**
     * Run script
     *
     */
    public function run()
    {
    	
    	$collection = Mage::getModel('catalog/product')->getCollection()
    	->addAttributeToFilter('type_id', array('eq'=>'simple'))
    	//->addAttributeToFilter('visibility',array('neq'=>4))
    	;
    	foreach ($collection as $product) {
    		
    		$prod = Mage::helper('catalog/product')->getProduct($product->getId(), null, null);
    		
    		if (count($prod->getMediaGallery('images')) == 0) {
    			var_dump('SKU:' . $prod->getSku() . ' has no images');
    			
    		}
    		else {
    			var_dump('SKU:' . $prod->getSku() . ' has images');
    			$prod->setData('visibility',4);
    			$prod->save();
    			var_dump('SKU:' . $prod->getSku() . ' update visibility to 4');
    		}
    		
    	}
    	
    	
    }
}

$shell = new Mage_Shell_UpdateHasImageSimpleProductVisibility();
$shell->run();

 

你可能感兴趣的:(visibility)