Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Magento中重命名属性代码?_Magento_Attributes_Magento 1.4_Entity Attribute Value - Fatal编程技术网

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

如何在Magento中重命名属性代码?,magento,attributes,magento-1.4,entity-attribute-value,Magento,Attributes,Magento 1.4,Entity Attribute Value,我想将现有属性的代码重命名为其他代码。这是因为属性字段是为300多种产品填写的,我不想仅仅因为更改了属性的代码就必须重新导入所有这些产品。您可以在mysql中编辑它,网址为eav\u attribute.attribute\u code。确保在备份之前进行备份,然后在系统>索引管理中重新编制索引。使用以下脚本: <?php $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $write

我想将现有属性的代码重命名为其他代码。这是因为属性字段是为300多种产品填写的,我不想仅仅因为更改了属性的代码就必须重新导入所有这些产品。

您可以在mysql中编辑它,网址为
eav\u attribute.attribute\u code
。确保在备份之前进行备份,然后在
系统>索引管理中重新编制索引。

使用以下脚本:

<?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'
    )
");

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

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

编辑属性代码并重新编制索引后,您还可能会发现需要清除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缓存和Flush Cache存储的详细信息,请参见:

这篇文章中重要的一段是

对于那些使用Magento的默认文件系统缓存的人来说,这似乎微不足道。您只需进入并手动“rm-rf var/cache/*”即可清除缓存。但是那些使用备用缓存类型(xcache、memcached、apc、db、sqlite)的人,“Flush-Magento-cache”可能没有完成您希望它完成的任务。因此,当所有其他操作都失败时,您希望确保缓存完全清除,请务必单击“刷新缓存存储”

在我说再见之前有一个警告,如果您使用的是一种共享存储缓存类型,例如两个不同的应用程序使用相同的memcached实例,那么单击“刷新缓存存储”也可能会删除另一个应用程序的缓存项。这可能不是你想要的,所以请注意


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

$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();
$installer = $this;
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'old_attribute_code', array('attribute_code' => 'new_attribute_code'));
$installer->endSetup();
除了完整的安装脚本,您还可以从简单的文件运行它,只需替换

$installer = $this;


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

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

如果不明显,您必须编辑代码,无论它在哪里使用

刚刚在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'
);

当您已经知道现有的
属性代码时,为什么要使用子查询来查找
属性id
?如何使用magneto 2执行此操作?如何使用直接在SQL中的magento 2执行此操作?