2016-03-21 13 views
1

私は自分の顧客テーブルに追加されるカスタムEAV属性を作成しましたが、それを設定する関数を作成しようとしています。カスタムEAV属性にデータを保存する

$customer = Mage::getModel("customer/customer")->load(22); 
    $customer->setProfession("aaaaaaaaaaaaaaaaaaaa"); 
    $customer->save(); 

しかし、いくつかの理由でそれを保存していない:

は、私が現在持っていることです。ファーストネームのような標準フィールドを設定することはできますが、自分が作成したカスタムEAVアトリビュートを保存することは困難です。

誰でも助けてください。

答えて

2

まず、 をsetData()関数でテストし、正しい属性名を使用していることを検証します。

$customer->setData('profession', 'some profession');er code here 

次に、 この属性はどのように作成しましたか?私はこのようにそれを行うことをお勧めします (中/インストールファイル.PHPのアップグレード):

$installer = $this; 
$installer->startSetup(); 
$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 
$entityTypeId = $setup->getEntityTypeId('customer'); 
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); 
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); 

//drop attribute if it already exists (to avoid problems) 
$setup->removeAttribute('customer', 'profession'); 
//now recreate the attribute 
$this->addAttribute('customer', 'profession', array(
'type' => 'varchar', 
'input' => 'text', 
'label' => Mage::helper('core')->__("Customer profession"), 
'global' => 1, 
'visible' => 1, 
'required' => 0, 
'user_defined' => 1, 
'visible_on_front' => 1)); 
//adding the attribute in backend Forms in case you want that 
Mage::getSingleton('eav/config') 
    ->getAttribute('customer', 'profession') 
    ->setData('used_in_forms', array('adminhtml_customer', 'customer_edit')) 
    ->save(); 

は、それはあなたのために今働くなら、私に教えてください。

関連する問題