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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.