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

时间:2015-03-30 10:30:59

标签: magento

我有一个带有一些属性前端标签的属性。但我想更改产品的frontendlabel。是否有magento提供的任何功能以编程方式执行此操作。

如果是,怎么办?

谢谢,

3 个答案:

答案 0 :(得分:6)

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

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();

答案 1 :(得分:1)

如果要为每个商店视图设置前端商店标签,可以采用下一种方式(此代码用于custemer属性,但您可以通过这种方式为所有类型的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();

答案 2 :(得分:1)

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

$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)是最适合的功能。