【发布时间】:2011-03-04 19:21:23
【问题描述】:
我想将现有属性的代码重命名为其他名称。原因是属性字段填写了 300 多个产品,我不想仅仅因为我更改了属性的代码而重新导入所有这些。
【问题讨论】:
标签: magento attributes magento-1.4 entity-attribute-value
我想将现有属性的代码重命名为其他名称。原因是属性字段填写了 300 多个产品,我不想仅仅因为我更改了属性的代码而重新导入所有这些。
【问题讨论】:
标签: magento attributes magento-1.4 entity-attribute-value
您可以在eav_attribute.attribute_code 的mysql 中编辑它。请务必先进行备份,然后在 System>Index Management 中重新索引所有内容。
【讨论】:
使用具有以下内容的升级脚本要容易得多:
$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();
【讨论】:
如果您可以访问数据库,则可以运行此 SQL 命令
UPDATE eav_attribute
SET attribute_code = 'your_NEW_attribute_code'
WHERE attribute_code = 'your_OLD_attribute_code'
之后不要忘记重新索引和编辑您的 sql 代码
【讨论】:
使用具有以下内容的升级脚本要容易得多 为此:
$installer = $this; $installer->startSetup(); $installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code')); $installer->endSetup();
您也可以从简单文件中运行它,而不是完整的安装脚本,只需替换
$installer = $this;
与
require_once('./app/Mage.php');
Mage::app();
$installer = Mage::getModel('eav/entity_setup', 'core_setup');
...
【讨论】:
从以下脚本中获取灵感:
<?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'
)
");
【讨论】:
attribute_code,为什么还要使用子查询来查找attribute_id?
在编辑 attribute_code 并重新索引 all 后,您可能还会发现需要清除 magento 缓存,包括 Flush Magento Cache 和 Flush Cache Storage - 或者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)的人,“Flush Magento Cache”可能没有做你想做的事。因此,当所有其他方法都失败并且您想确保缓存完全清除时,请务必点击“刷新缓存存储”。
在我说再见之前有一个警告,如果您使用的是共享存储缓存类型之一 - 例如两个不同的应用程序使用相同的 memcached 实例 - 单击“刷新缓存存储”可能会删除该其他应用程序的缓存条目好。这可能不是您想要的,所以请注意。
【讨论】:
刚刚在 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'
);
【讨论】: