2

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.

3

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.

  • Thanks. That might work (not tested yet) but I would like to be able to review before deleting. Is it possible to somehow add a column in the admin interface to show if the account is confirmed? – george Jun 26 '15 at 11:33
  • 1
    Please check my updated response. – Abhilash Acharya Jun 26 '15 at 16:55
  • Thanks for the update. The column gets added to the grid but the whole table becomes empty (no customers shown at all). No errors in log too. It seems to me there might be some error in the join statement but I don't know what it might be. BTW there is some function getIsConfirmedStatus() in /Block/Customer/Edit/Tab/View.php. Is it possible to use it somehow instead of risking a wrong attribute_id (e.g. if this local code gets applied on another Magento site)? Unfortunately I don't know how to do it properly, I hope you can help. – george Jun 27 '15 at 17:54
  • 1
    Yes, the left join will be also fine. I tested this on Magento enterprise 1.14.2, and it worked, I think your answer is correct. But I'll also check it again and update here :) – Abhilash Acharya Jun 29 '15 at 3:36
  • 1
    I have updated it. For confirmed users it will be blank. Thanks. – Abhilash Acharya Jun 29 '15 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.