2012-05-02 5 views
1

Magentoのドロップダウン属性のオプションを(プログラムで)コードを使って更新/追加したい。属性オプションを追加する方法を見つけましたが、オプション値をどのように更新できますか?
例:
属性が「製造元」であるとします。私は3つのオプションman1、man2、man3を追加しました。今私のカスタムコードを介して、man1とman2のラベルをman22に変更したいと思います。それをどうすれば実現できますか?おかげさまで Magentoで属性オプションをプログラムで更新するにはどうすればよいですか?

答えて

2

まあ、自分で解決策を見つけました。 See complete details here

//Get the eav attribute model 
$attr_model = Mage::getModel('catalog/resource_eav_attribute'); 

//Load the particular attribute by id 
//Here 73 is the id of 'manufacturer' attribute 
$attr_model->load(73); 

//Create an array to store the attribute data 
$data = array(); 

//Create options array 
$values = array(
    //15 is the option_id of the option in 'eav_attribute_option_value' table 
    15 => array(
      0 => 'Apple' //0 is current store id, Apple is the new label for the option 
     ), 
    16 => array(
      0 => 'HTC' 
     ), 
    17 => array(
      0 => 'Microsoft' 
     ), 
); 

//Add the option values to the data 
$data['option']['value'] = $values; 

//Add data to our attribute model 
$attr_model->addData($data); 

//Save the updated model 
try { 
    $attr_model->save(); 
    $session = Mage::getSingleton('adminhtml/session'); 
    $session->addSuccess(
     Mage::helper('catalog')->__('The product attribute has been saved.')); 

    /** 
    * Clear translation cache because attribute labels are stored in translation 
    */ 
    Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG)); 
    $session->setAttributeData(false); 
    return; 
} catch (Exception $e) { 
    $session->addError($e->getMessage()); 
    $session->setAttributeData($data); 
    return; 
} 
0

app \ code \ core \ Mage \ Adminhtml \ controllers \ Catalog \ Product \ AttributeController.phpにあるAttributeControllerを拡張し、必要に応じてsaveAction()メソッドをオーバーライドするとよいでしょう。

+0

saveAction()では、すべての設定を属性に設定する必要があります。しかし、他の設定ではなくオプションラベルを更新したいだけです。 –

関連する問題