如何在Magento中使用sql查询更新产品名称? [英] How can I update the product name with a sql query in Magento?

查看:73
本文介绍了如何在Magento中使用sql查询更新产品名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我要在所有产品名称"example"中替换为"test".我该怎么做?

Now, I want to replace in all product names 'example' with 'test'. How do I do this?

我不知道产品名称存储在数据库中的什么位置?我应该如何编写sql命令?

I don't know where the product name is stored in the database? How should I write the sql command?

我知道sql命令将会

 update table_name set product_name = replace(value,"example","test")

如何在Magento中更改它?

How do I change it in Magento?

推荐答案

通常,使用sql直接更新magento数据库是一个坏主意.我建议您创建一个控制器,在其中可以轻松运行以下小脚本:

Generally, it's a bad idea to directly update your magento database using sql. I'd recommend you create a controller, where you can easily run this little script:

public function databaseAction() {
    // load all products where 'name' LIKE '%example%'
    $products = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('name')
                ->addFieldToFilter(array(
                        array('attribute' => 'name', 'like' => '%example%')
                ));

    // loop through products, update the product name and save the product
    foreach ($products as $product) {
        $product->setName(str_replace('example', 'test', $product->getName()));
        $product->save();
    }
}

这篇关于如何在Magento中使用sql查询更新产品名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆