如何在 Magento 中重命名属性代码?

发布于 2024-10-20 05:57:28 字数 76 浏览 11 评论 0原文

我想将现有属性的代码重命名为其他名称。原因是因为属性字段已填写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

泅人 2024-10-27 05:57:28

您可以在 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 in System>Index Management afterwards.

陈年往事 2024-10-27 05:57:28

使用包含以下内容的升级脚本要容易得多:

$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();

It is much easier to use an upgrade script with the following content for that:

$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();
岁吢 2024-10-27 05:57:28

如果您有权访问数据库,则可以运行此 SQL 命令,

UPDATE eav_attribute
SET   attribute_code = 'your_NEW_attribute_code'
WHERE attribute_code = 'your_OLD_attribute_code'

之后不要忘记重新索引并编辑您的 sql 代码。
请注意,不建议在实时环境中进行更新,它真的会把事情搞砸

if you have access to the database, you can run this SQL command

UPDATE eav_attribute
SET   attribute_code = 'your_NEW_attribute_code'
WHERE attribute_code = 'your_OLD_attribute_code'

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.

谁对谁错谁最难过 2024-10-27 05:57:28

使用包含以下内容的升级脚本要容易得多
为此:

$installer = $this;
$安装程序->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$安装程序->endSetup();

您也可以从简单文件运行此脚本,而不是完整的安装脚本,只需替换

$installer = $this;

require_once('./app/Mage.php');
Mage::app();

$installer  = Mage::getModel('eav/entity_setup', 'core_setup');
...

It is much easier to use an upgrade script with the following content
for that:

$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();

Instead of a full install script you can run this also from simple file, just replace

$installer = $this;

with

require_once('./app/Mage.php');
Mage::app();

$installer  = Mage::getModel('eav/entity_setup', 'core_setup');
...
半城柳色半声笛 2024-10-27 05:57:28

从以下脚本中汲取灵感:

<?php
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
  UPDATE eav_attribute val
  SET  val.attribute_code = "SET VALUE WHAT YOU WANT"
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4
       AND eav.attribute_code = 'price'
    )
");

Take inspiration the following script :

<?php
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
  UPDATE eav_attribute val
  SET  val.attribute_code = "SET VALUE WHAT YOU WANT"
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4
       AND eav.attribute_code = 'price'
    )
");
面犯桃花 2024-10-27 05:57:28

编辑 attribute_code 并重新索引所有内容后,您可能还会发现需要清除 magento 缓存,包括刷新 Magento 缓存和刷新缓存存储 - 或者 rm -rf var/cache/* (请参阅下文注意事项)。

Magento 使用缓存来存储 Mage::getSingleton('catalog/product')->loadByAttribute('sku',$sku); 引用的查询以及可能的其他类似调用。像这样的查询:

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, `e`.`entity_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`cost`, `e`.`created_at`, `e`.`enable_googlecheckout`, `e`.`gift_message_available`, `e`.`has_options`, `e`.`image_label`, `e`.`is_recurring`, `e`.`links_exist`, `e`.`links_purchased_separately`, `e`.`links_title`, `e`.`manufacturer`, `e`.`manufacturer_value`, `e`.`name`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`price`, `e`.`price_type`, `e`.`price_view`, `e`.`recurring_profile`, `e`.`required_options`, `e`.`shipment_type`, `e`.`short_description`, `e`.`sku`, `e`.`sku_type`, `e`.`small_image`, `e`.`small_image_label`, `e`.`special_from_date`, `e`.`special_price`, `e`.`special_to_date`, `e`.`tax_class_id`, `e`.`thumbnail`, `e`.`thumbnail_label`, `e`.`updated_at`, `e`.`url_key`, `e`.`url_path`, `e`.`visibility`, `e`.`weight`, `e`.`weight_type`, `e`.`[CUSTOM_ATTRIBUTE_CODE]`, `e`.`[CUSTOM_ATTRIBUTE_CODE]` FROM `catalog_product_flat_1` AS `e` WHERE (e.sku = '[SKU]') LIMIT 1

有关 Flush Magento Cache 和 Flush Cache Storage 功能的更多信息,请参见此处:
http://blog.nexcess.net/2011 /05/21/clearing-the-cache-in-magento/

文章中重要的一段是这个

对于那些使用 Magento 的默认文件系统缓存的人来说,这可能看起来微不足道。您可以手动输入“rm -rf var/cache/*”来清除缓存。但是如果您使用其他缓存类型(xcache、memcached、apc、db、sqlite),“刷新 Magento 缓存”可能不会执行您希望它执行的操作。因此,当所有其他方法都失败并且您想确保缓存完全清除时,请务必单击“刷新缓存存储”。

在我说再见之前,需要注意的是,如果您正在使用其中一种共享存储缓存类型 - 例如两个不同的应用程序使用相同的 memcached 实例 - 单击“刷新缓存存储”可能会删除该其他应用程序的缓存条目,如下所示出色地。这可能不是您想要的,所以请注意。

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:

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, `e`.`entity_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`cost`, `e`.`created_at`, `e`.`enable_googlecheckout`, `e`.`gift_message_available`, `e`.`has_options`, `e`.`image_label`, `e`.`is_recurring`, `e`.`links_exist`, `e`.`links_purchased_separately`, `e`.`links_title`, `e`.`manufacturer`, `e`.`manufacturer_value`, `e`.`name`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`price`, `e`.`price_type`, `e`.`price_view`, `e`.`recurring_profile`, `e`.`required_options`, `e`.`shipment_type`, `e`.`short_description`, `e`.`sku`, `e`.`sku_type`, `e`.`small_image`, `e`.`small_image_label`, `e`.`special_from_date`, `e`.`special_price`, `e`.`special_to_date`, `e`.`tax_class_id`, `e`.`thumbnail`, `e`.`thumbnail_label`, `e`.`updated_at`, `e`.`url_key`, `e`.`url_path`, `e`.`visibility`, `e`.`weight`, `e`.`weight_type`, `e`.`[CUSTOM_ATTRIBUTE_CODE]`, `e`.`[CUSTOM_ATTRIBUTE_CODE]` FROM `catalog_product_flat_1` AS `e` WHERE (e.sku = '[SKU]') LIMIT 1

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

This may seem trivial to those of you using the default filesystem cache with Magento. You can just go in and manually “rm -rf var/cache/*” to clear the cache out. But those of you using the alternate cache types (xcache, memcached, apc, db, sqlite), the “Flush Magento Cache” may not be doing what you want it to do. So, when all else fails and you want to be sure the cache is totally clear, be sure to click on “Flush Cache Storage”.

One caveat before I say farewell, if you are using one of the shared storage cache types – for example two different apps using the same memcached instance – clicking on “Flush Cache Storage” might remove the cache entries for that other application as well. This may not be what you want, so just take heed.

赤濁 2024-10-27 05:57:28

刚刚在 Magento 2.4 上测试过

/** @var \Magento\Customer\Setup\CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->updateAttribute(
    Customer::ENTITY,
    'old_attribute_code',
    'attribute_code', // don't change this one
    'new_attribute_code'
);

Just tested on Magento 2.4

/** @var \Magento\Customer\Setup\CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->updateAttribute(
    Customer::ENTITY,
    'old_attribute_code',
    'attribute_code', // don't change this one
    'new_attribute_code'
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文