获取Magento中设置为customer的属性的默认值

时间:2012-03-05 14:17:00

标签: magento entity-attribute-value

我正在使用基于某些规则切换客户群的扩展程序。 我使用此代码将一个属性作为EAV添加到客户。

$setup->addAttribute('customer', 'autoswitchgroup', array(
    'type' => 'varchar',
    'input' => 'select',
    'label' => 'Autoswitch Group',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'default' => 'yes',
    'visible_on_front' => 1,
    'source' => 'bitstream_all/entity_autoswitchgroup',
));

查看扩展程序代码,我看到它使用以下代码获取客户属性:

$customerAttributeValue = $this->_getCustomer()->getDataUsingMethod($attribute);

其中_getCustomer()被定义为Object。 (@return Varien_Object)。

如果我查看客户对象,我会看到以下信息:

[_resourceCollectionName:protected] => customer/customer_collection
    [_cacheTag:protected] => 
    [_dataSaveAllowed:protected] => 1
    [_isObjectNew:protected] => 
    [_data:protected] => Array
        (
            [entity_id] => 1
            [entity_type_id] => 1
            [attribute_set_id] => 0
            [website_id] => 1
            [email] => ****
            [group_id] => 11
            [increment_id] => 000000001
            [store_id] => 1
            [created_at] => 2011-06-04 15:11:50
            [updated_at] => 2012-03-05 14:04:54
            [is_active] => 1
            [created_in] => Lenjerii
            [prefix] => 
            [firstname] => Ovidiu
            [middlename] => 
            [lastname] => Ungureanu
            [suffix] => 
            [password_hash] => ****
            [taxvat] => 
            [facebook_uid] => ****
            [gender] => 1
            [dob] => 
            [autoswitchgroup] => yes
            [is_subscribed] => 1
            [parent_id] => 0
            [dob_is_formated] => 1
            [confirmation] => 
        )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => Array
        (
            [entity_id] => 1
            [entity_type_id] => 1
            [attribute_set_id] => 0
            [website_id] => 1
            [email] => ****
            [group_id] => 11
            [increment_id] => 000000001
            [store_id] => 1
            [created_at] => 2011-06-04 15:11:50
            [updated_at] => 2012-03-05 13:49:46
            [is_active] => 1
            [created_in] => Lenjerii
            [prefix] => 
            [firstname] => Ovidiu
            [middlename] => 
            [lastname] => Ungureanu
            [suffix] => 
            [password_hash] => ****
            [taxvat] => 
            [facebook_uid] => ****
            [gender] => 1
        )

    [_idFieldName:protected] => entity_id
    [_isDeleted:protected] => 

在前端我想要相同的信息,使用它获取它: $ customer = Mage :: getSingleton('customer / session') - > getCustomer();

结果如下:

[_resourceCollectionName:protected] => customer/customer_collection
    [_cacheTag:protected] => 
    [_dataSaveAllowed:protected] => 1
    [_isObjectNew:protected] => 
    [_data:protected] => Array
        (
            [website_id] => 1
            [entity_id] => 1
            [entity_type_id] => 1
            [attribute_set_id] => 0
            [email] => ***
            [group_id] => 11
            [increment_id] => 000000001
            [store_id] => 1
            [created_at] => 2011-06-04 15:11:50
            [updated_at] => 2012-03-05 13:49:46
            [is_active] => 1
            [created_in] => Lenjerii
            [prefix] => 
            [firstname] => Ovidiu
            [middlename] => 
            [lastname] => Ungureanu
            [suffix] => 
            [password_hash] => ***
            [taxvat] => 
            [facebook_uid] => ***
            [gender] => 1
            [tax_class_id] => 3
        )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => Array
        (
            [website_id] => 1
            [entity_id] => 1
            [entity_type_id] => 1
            [attribute_set_id] => 0
            [email] => ***
            [group_id] => 11
            [increment_id] => 000000001
            [store_id] => 1
            [created_at] => 2011-06-04 15:11:50
            [updated_at] => 2012-03-05 13:49:46
            [is_active] => 1
            [created_in] => Lenjerii
            [prefix] => 
            [firstname] => Ovidiu
            [middlename] => 
            [lastname] => Ungureanu
            [suffix] => 
            [password_hash] => ****
            [taxvat] => 
            [facebook_uid] => ****
            [gender] => 1
        )

我有兴趣得到它[autoswitchgroup] - 创建的属性。这个没有保存在所有用户的数据库显式中,这就是我有一个默认值的原因。 现在我不明白的是我在模块中如何获得客户数据,但在前端我看不到它。

更重要的是,模块出现在[_data:protected]中,但不出现在[_origData:protected]中。

在这两个地方,对象都是_resourceCollectionName:protected] => customer / customer_collection ...

希望这不会太久阅读。

1 个答案:

答案 0 :(得分:0)

我知道这不是一个真正的答案,但这就是我所做的和工作。

$attribute = 'autoswitchgroup';
$customer->getDataSetDefault($attribute, 'yes');

因此,我获取属性名称,并且如果没有值,则使用该属性的getDataSetDefault将设置默认值。