Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Foreach loops breaking code?

$
0
0

So I'm trying to write a script that will reset some values in a Magento product database, but I'm having some issues. I need to code to run for all products, in all stores, for all th attributes. I wrote the inital little script, and it works fine:

$product_id = 1657;
$store_id = 4;
$attr = 'name';

$product = Mage::getModel('catalog/product')
    	->load($product_id)         
    	->setStoreId($store_id)     
    	->setData($attr, false)    
    	->save(); 

The issue is, I need it to run for all products, all stores, all attributes. My next step was to test it with one attribute, one store, all products, and my code was:

$product_ids = Mage::getModel('catalog/product')->getCollection()->getAllIds();
$store_id = 4;
$attr = 'name';

foreach ($product_ids as $product_id){
	$product = Mage::getModel('catalog/product')
    	->load($product_id)         
    	->setStoreId($store_id)     
    	->setData($attr, false)    
    	->save(); 
}

That code gets me no results. If I run the foreach loop and print_r the $product_ids the array contains what I think it should. Anyone have any ideas? I haven't even started to touch the multiple attributes in multiple stores since this doesn't work yet.


Viewing all articles
Browse latest Browse all 13200

Trending Articles