0
votes

I'm using an extension that switch customer groups based on some rules. I added an attribute to customer as an EAV using this code.

$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',
));

Looking over the extension code I see it gets the customer attribute using this code:

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

where _getCustomer() is defined as an Object. (@return Varien_Object).

If I take a look on the customer object I see this info:

[_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] => 

In frontend I want the same info, getting it using this: $customer = Mage::getSingleton('customer/session')->getCustomer();

Here is the result:

[_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
        )

What I'm interested to get it [autoswitchgroup] - the attribute created. This one is not saved in database explicity for all users, that's why I have a default value. Now what I don't understand is how on module I get it in customer data but on frontend I don't see it.

Even more, on module appears in [_data:protected] but not in [_origData:protected].

In both places the object is _resourceCollectionName:protected] => customer/customer_collection ...

Hopefully this is not too long to read.

1
There might be an customer_load_after event observer registered for the adminhtml area only. In that observer method the default value might be set. Just an idea.Vinai
Can't you retrieve the value using a magic get? Like $customer->getAutoswitchgroup()?seanbreeden
@seanbreeden no, is not working.Ovidiu
@Vinai, could be, I'm not that proficiency in magento to digg it :)Ovidiu

1 Answers

0
votes

I know is not an real answer but here is what I did and works.

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

So, I get the attribute name and using getDataSetDefault for that attribute will set a default value if there is no value.