chastainator Posted March 8, 2013 Share Posted March 8, 2013 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 More sharing options...
requinix Posted March 8, 2013 Share Posted March 8, 2013 So what did the print_r() output? It should look like Array ( [0] => 123 [1] => 234 [2] => 345 ) Link to comment https://forums.phpfreaks.com/topic/275415-foreach-loops-breaking-code/#findComment-1417562 Share on other sites More sharing options...
AyKay47 Posted March 8, 2013 Share Posted March 8, 2013 What does a print_r() yield? Link to comment https://forums.phpfreaks.com/topic/275415-foreach-loops-breaking-code/#findComment-1417563 Share on other sites More sharing options...
chastainator Posted March 8, 2013 Author Share Posted March 8, 2013 the print_r gave me an array like this, just bigger and not formatted all pretty. So what did the print_r() output? It should look like Array ( [0] => 123 [1] => 234 [2] => 345 ) Link to comment https://forums.phpfreaks.com/topic/275415-foreach-loops-breaking-code/#findComment-1417574 Share on other sites More sharing options...
Barand Posted March 8, 2013 Share Posted March 8, 2013 Couldn't you run a query to update the database table Link to comment https://forums.phpfreaks.com/topic/275415-foreach-loops-breaking-code/#findComment-1417578 Share on other sites More sharing options...
chastainator Posted March 8, 2013 Author Share Posted March 8, 2013 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 https://forums.phpfreaks.com/topic/275415-foreach-loops-breaking-code/#findComment-1417582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.