I have a Magento 1.5.0.1 install with 3 different store views. At some point along the way two of the stores dont use the default values for product attributes. I am trying to find a way to make all products use default values for all stores, that way the client only has to update things in one place. I found this article but it seems like it only applies to specifically called products. Can anyone explain how to employ that code in my situation? Or suggest new code?
Asked
Active
Viewed 6,695 times
1
-
You have any idea when the entries created for other stores. – Sankar Subburaj May 07 '13 at 12:57
3 Answers
9
The only way I could get this to work was via MySQL:
DELETE FROM `catalog_product_entity_text` where store_id != 0;
DELETE FROM `catalog_product_entity_datetime` where store_id != 0;
DELETE FROM `catalog_product_entity_decimal` where store_id != 0;
DELETE FROM `catalog_product_entity_int` where store_id != 0;
DELETE FROM `catalog_product_entity_varchar` where store_id != 0;
The above will reset all products to use default values for all attributes.

JaseC
- 3,103
- 2
- 21
- 22
0
You should use the Mage::getSingleton('catalog/product_action') to update a lot of product in a row.
1°) Get the ids of product you want, for all product use :
$ids = Mage::getModel('catalog/product')->getCollection()->getAllIds();
2°) Make the list of the attribute and associate the value "false"
$attributes = array('name'=>false,'description'=>false,....)
3°) Pick up the list of store ids to change and set it in an array too :
$stores = array(1,2,3);
Then create your script :
foreach ($stores as $store_id)
{
Mage::getSingleton('catalog/product_action')->updateAttributes($ids, $attributes, $store_id);
}
It will update all products (ids) to set the attributes to default (thanks to the "false" value) in the store_id.

dagfr
- 2,349
- 1
- 19
- 22
-
Ok so I've created my script file here: http://pastebin.com/yc9BY8XC and I uploaded to the my magento root, made executable and ran it, but I got errors. Can you help me figure this think out? – Alex Chastain Mar 04 '13 at 19:38
-
could you try with just 1 attribute ? What is the error message you have ? – dagfr Mar 04 '13 at 20:38
-
I tried to run it from an SSH session and it gave me errors that didn't make any sense. Then i browsed to the file using a web browser, and the script seemed to run because now the store doesn't show any products on the front end. The script seems to have cleared all the fields on all products, but not check the "Use Default" boxes. Any ideas? My full script is here: http://pastebin.com/fpv6qxGi – Alex Chastain Mar 05 '13 at 22:10
0
This will take values that have been set on any store and merge those into the default values for all products:
<?php
$cat = mysql_connect("host", "user", "password") or die(mysql_error());
mysql_select_db("database",$cat) or die(mysql_error());
$types = array(
'catalog_product_entity_text',
'catalog_product_entity_datetime',
'catalog_product_entity_decimal',
'catalog_product_entity_int',
'catalog_product_entity_varchar'
);
foreach($types as $type){
$result = mysql_query("select * from $type where store_id != 0",$cat) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
if(!is_null($row['value'])){
mysql_query("update $type set value = '".mysql_real_escape_string(stripslashes($row['value']))."'
where store_id = '0'
and entity_id = '".$row['entity_id']."'
and attribute_id = '".$row['attribute_id']."'",$cat) or die(mysql_error());
}
mysql_query("delete from $type where value_id = '".$row['value_id']."'",$cat) or die(mysql_error());
}
}
?>

JaseC
- 3,103
- 2
- 21
- 22