以编程方式更新 magento 中属性的前端标签?

update the frontend label of an attribute in magento programmatically?

我有一个带有某些属性前端的属性 label.But 我想更改 product.Is 的前端标签,magento 中提供了任何函数来以编程方式执行此操作。

如果是,请问如何实现???

谢谢,

如果你想为每个商店视图设置前端商店标签,你可以用下面的方法来做(此代码用于客户属性,但你可以通过这种方式为所有类型的 EAV 属性设置前端标签。):

$installer->startSetup();

$attribute = array(
    'entity_type' => 'customer',
    'code' => 'customer_type_id',
    'translations' => array(
        'store_code_en_en' => 'english name',
        'store_code_at_de' => 'german name',
        'store_code_fr_fr' => 'franch name'
    )
);

$storeLabels = array();
foreach ($attribute['translations'] as $storeViewCode => $text) {
    $storeViewId = Mage::getModel('core/store')->load($storeViewCode, 'code')->getId();
    $storeLabels[$storeViewId] = $text;
}

$attributeId = $installer->getAttributeId($attribute['entity_type'], $attribute['code']);
Mage::getSingleton('eav/config')->getAttribute($attribute['entity_type'], $attributeId)
    ->setData('store_labels', $storeLabels)
    ->save();

$installer->endSetup();

我找到了更简单的问题解决方案...

$attributeId = Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product', 'ATTRIBUTE_CODE');
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attribute->setFrontendLabel($displayName)->save();

setFrontendLabel(string $str) 是最适合这里的函数。

最安全的方法是加载现有标签,然后添加新的商店特定标签:

1 - 检索所有商店的现有标签

Mage::getModel('eav/entity_attribute')->getResource()
   ->getStoreLabelsByAttributeId($attributeId);

$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$labels= $attribute->getStoreLabels();

2 - 添加自定义标签

$labels[$storeId] = 'My new label for a specific store';

$attribute->setStoreLabels($labels)->save();