2013-02-25 57 views
1

我有一个Magento 1.5.0.1安装与3个不同的商店意见。在此过程中,有两个商店不使用产品属性的默认值。我试图找到一种方法让所有产品都使用所有商店的默认值,这样客户端只需要在一个地方进行更新。我发现this文章,但它似乎只适用于专门称为产品。任何人都可以解释如何在我的情况下使用该代码?或者建议新的代码?设置所有商品默认值全部商店

+0

您有任何想法条目其他商店创建时。 – 2013-05-07 12:57:20

回答

6

我能得到这个工作的唯一办法是通过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; 

以上将重置所有产品中使用默认值的所有属性。

+0

这工作伟大的人感谢! – 2013-04-03 17:31:31

0

您应该使用Mage :: getSingleton('catalog/product_action')来更新连续的很多产品。

1°)得到你想要的产品的ID,对所有产品使用:

$ids = Mage::getModel('catalog/product')->getCollection()->getAllIds(); 

2°)使属性的列表和值相关联的 “假”

$attributes = array('name'=>false,'description'=>false,....) 

3°)拿起店内的ID列表改变,并将其设置在数组中太:

$stores = array(1,2,3); 

然后创建脚本:

foreach ($stores as $store_id) 
{ 
    Mage::getSingleton('catalog/product_action')->updateAttributes($ids, $attributes, $store_id); 
} 

将所有产品都更新(IDS)来设置属性在STORE_ID默认(感谢“假”值)。

+0

好的,我在这里创建了我的脚本文件:http://pastebin.com/yc9BY8XC和我上传到我的magento根,制作可执行文件并运行它,但我得到错误。你能帮我弄清楚这个想法吗? – 2013-03-04 19:38:48

+0

你可以尝试只有一个属性?你有什么错误信息? – dagfr 2013-03-04 20:38:17

+0

我试图从SSH会话中运行它,它给了我没有任何意义的错误。然后,我使用网络浏览器浏览文件,脚本似乎运行,因为现在商店没有在前端显示任何产品。该脚本似乎清除了所有产品上的所有字段,但未检查“使用默认值”框。有任何想法吗?我的完整脚本在这里:http://pastebin.com/fpv6qxGi – 2013-03-05 22:10:52

0

这将需要已设置的任何存储值和合并那些到默认值的所有产品:

 <?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()); 

     } 

    } 
?>