Jump to content

Foreach loops breaking code?


chastainator

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/275415-foreach-loops-breaking-code/
Share on other sites

As far as I can find it doesn't store the info in the database, when the value is false, it deletes the record from the db and defaults to what I need. The problem is the db is huge and I can't seem to make heads or tails of the structure. I spent a few days researching and it all came back to scripting php instead of dealing with the db directly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.