Question

Is there a way to find and list the customer accounts in Magento's backend (or programatically) which have not been confirmed?

I would like to run this check and cleanup periodically as it often happens people make typos in their email address and register twice and one of the accounts is never used.

Was it helpful?

Solution

Create a test.php file in your root folder of magento, then put the following code and run it, it will delete all the unconfirmed customers in magento.

  <?php 
ini_set("display_errors", true);
require_once 'app/Mage.php';
Mage::app('default');
umask(0);   
   $result = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('confirmation', array('notnull' => true));
   foreach($result as $res){
 try{
     Mage::getModel('customer/customer')->load($res->getId())->delete();
     Mage::log($res->getEmail(). " DELETED",null, 'unconfirmed_delete.log');
 }catch(Exception $e){
      Mage::log($e->getMessage() ,null, 'unconfirmed_delete.log');
}
  }

You can see the deleted customer emails in unconfirmed_delete.log file in var/log folder.

cheers

UPDATE:

To view it in backend, you need to do some changes in

  app/code/core/Mage/Adminhtml/Block/Customer/Grid.php

If you are not familiar with block override, you can just copy it to local in following path and do your changes there.

app/code/local/Mage/Adminhtml/Block/Customer/Grid.php

As it is a core file, you need to override it on local folder.

Step :1 (Update the _prepareCollection method):

Add below code at the bottom.

->joinField('confirmation',
            'customer_entity_varchar',
            'attribute_id',
            'entity_id=entity_id',
            "{{table}}.attribute_id='16'",'left');

The new _prepareCollection method will be like:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('confirmation')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')

        ->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', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
       ->joinField('confirmation',
            'customer_entity_varchar',
            'attribute_id',
            'entity_id=entity_id',
            "{{table}}.attribute_id='16'",'left');

    $this->setCollection($collection);

    return parent::_prepareCollection();
}

Here 16 is the id of confirmation attribute. Means is 'attribute_id' from eav_attribute table where attribute_code is equal "confirmation".

Step:2 (add a column in customer grid)

Add below code

 $this->addColumn('confirmation', array(
        'header'    => Mage::helper('customer')->__('Confirmation'),
        'width'     => '150',
        'index'     => 'confirmation'
 ));

before below code in _prepareColumns() method.

 $this->addColumn('action',
        array(
            'header'    =>  Mage::helper('customer')->__('Action'),
            'width'     => '100',
            'type'      => 'action',
            'getter'    => 'getId',
            'actions'   => array(
                array(
                    'caption'   => Mage::helper('customer')->__('Edit'),
                    'url'       => array('base'=> '*/*/edit'),
                    'field'     => 'id'
                )
            ),
            'filter'    => false,
            'sortable'  => false,
            'index'     => 'stores',
            'is_system' => true,
    ));

It will add a new column of "Confirmation" in admin manage customer grid. If it looks blank, that means the customer is verified.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top