【问题标题】:Set all products to use default values all stores将所有产品设置为使用默认值所有商店
【发布时间】:2013-02-25 23:15:49
【问题描述】:

我有一个 Magento 1.5.0.1 安装,有 3 个不同的商店视图。在某些时候,其中两家商店不使用产品属性的默认值。我试图找到一种方法让所有产品对所有商店都使用默认值,这样客户只需在一个地方更新东西。我找到了this 文章,但它似乎只适用于特定名称的产品。谁能解释如何在我的情况下使用该代码?或者建议新代码?

【问题讨论】:

  • 您知道什么时候为其他商店创建的条目。

标签: php magento


【解决方案1】:

我可以让它工作的唯一方法是通过 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;

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

【讨论】:

    【解决方案2】:

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

    1°) 获取您想要的产品 ID,供所有产品使用:

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

    2°) 制作属性列表并关联值“false”

    $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);
    }
    

    它将更新所有产品(id)以将 store_id 中的属性设置为默认值(感谢“false”值)。

    【讨论】:

    • 好的,所以我在这里创建了我的脚本文件:pastebin.com/yc9BY8XC 并上传到我的 magento 根目录,使其可执行并运行它,但我遇到了错误。你能帮我弄清楚这个想法吗?
    • 您可以尝试仅使用 1 个属性吗?你有什么错误信息?
    • 我尝试从 SSH 会话运行它,但它给了我没有任何意义的错误。然后我使用网络浏览器浏览到该文件,脚本似乎运行了,因为现在商店没有在前端显示任何产品。该脚本似乎已清除所有产品上的所有字段,但未选中“使用默认值”框。有任何想法吗?我的完整脚本在这里:pastebin.com/fpv6qxGi
    【解决方案3】:

    这将采用已在任何商店设置的值并将其合并到所有产品的默认值中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多