开发者

How to load not active customers in magento

I need to load only inactive customers from magento collection.

$collection = Mage::getModel('customer/customer')
    ->getCollection()
    ->addNameToSelect()
    ->addAttributeToSelect('email')
    ->addAttributeToSelect('created_at')
    ->addAttributeToSelect('group_id')
    ->addAttributeToSelect('confirmation') 
    ->addAttributeToSelect('*');`

  $collection 
    ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
    ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
    ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', nul开发者_JAVA百科l, 'left')
    ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
    ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

And from this collection i tried to add

$collection->getSelect()->where("e.is_active = 0 ");

But it throws exception and am not able to load only inactive customers inside admin custom module. Please help me on loading inactive customers.

Note: From front-end by default i setup all the customers registration as "is_active" to be 0 , so after admin approval only customers will be active. For that i need to load all those inactive customers.


Try $collection->addAttributeToFilter('is_active', 0)


According to this magento thread there could be a bug in definition of default attributes of Customer Entity. Try to look into Mage_Customer_Model_Entity_Customer, in this method:

protected function _getDefaultAttributes()
{
    return array(
        'entity_type_id',
        'attribute_set_id',
        'created_at',
        'updated_at',
        'increment_id',
        'store_id',
        'website_id'
    );
}

there should be:

protected function _getDefaultAttributes()
{
    return array(
        'entity_type_id',
        'attribute_set_id',
        'created_at',
        'updated_at',
        'increment_id',
        'store_id',
        'website_id',
        'is_active'
    );
}

If this is the case then Zyava's solution neither this one: $collection->addFieldToFilter('is_active', 0) won't probably work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜