如何在 Magento 中重命名属性代码?
我想将现有属性的代码重命名为其他名称。原因是因为属性字段已填写 300 多种产品,我不想仅仅因为更改了属性代码就必须重新导入所有这些产品。
I want to rename an existing attribute's code to something else. The reason is because the attribute field is filled out for 300+ products and I don't want to have to re-import all of those just because I changed the code of an attribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以在 mysql 中的
eav_attribute.attribute_code
处编辑它。请务必先进行备份,然后在系统>索引管理
中重新索引所有内容。You can edit it in mysql at
eav_attribute.attribute_code
. Be sure to take backups prior and re-index all inSystem>Index Management
afterwards.使用包含以下内容的升级脚本要容易得多:
It is much easier to use an upgrade script with the following content for that:
如果您有权访问数据库,则可以运行此 SQL 命令,
之后不要忘记重新索引并编辑您的 sql 代码。
但请注意,不建议在实时环境中进行更新,它真的会把事情搞砸。
if you have access to the database, you can run this SQL command
don't forget to re-index and edit your sql codes afterwards.
but beware that doing updates in a live environment is not recommended, it can really mess things up.
您也可以从简单文件运行此脚本,而不是完整的安装脚本,只需替换
为
Instead of a full install script you can run this also from simple file, just replace
with
从以下脚本中汲取灵感:
Take inspiration the following script :
编辑 attribute_code 并重新索引所有内容后,您可能还会发现需要清除 magento 缓存,包括刷新 Magento 缓存和刷新缓存存储 - 或者
rm -rf var/cache/*
(请参阅下文注意事项)。Magento 使用缓存来存储
Mage::getSingleton('catalog/product')->loadByAttribute('sku',$sku);
引用的查询以及可能的其他类似调用。像这样的查询:有关 Flush Magento Cache 和 Flush Cache Storage 功能的更多信息,请参见此处:
http://blog.nexcess.net/2011 /05/21/clearing-the-cache-in-magento/
文章中重要的一段是这个
After you edit the attribute_code and reindex all you may also find that you need to clear magento caches including Flush Magento Cache and Flush Cache Storage -- or alternately
rm -rf var/cache/*
(see below for caveats).Magento uses caches to store queries referenced by
Mage::getSingleton('catalog/product')->loadByAttribute('sku',$sku);
and possibly other similar calls. Queries like this one:More about what Flush Magento Cache and Flush Cache Storage do here:
http://blog.nexcess.net/2011/05/21/clearing-the-cache-in-magento/
The important paragraph in the article is this
刚刚在 Magento 2.4 上测试过
Just tested on Magento 2.4