2016-03-21 61 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(); 

讓我知道,如果現在爲你工作。

相關問題