Question

I have a script that loads Customers/Addresses into Magento, but sometimes it fails. I would like to pick up were I left of (I am transforming data from one DB to Magento). What is a cheap way to get the last inserted customers email?

SELECT email FROM customer_entity ORDER BY entity_id DESC LIMIT 1; 

Is that a safe/sane way to do this?

Was it helpful?

Solution

You can get last inserted customer id by magento customer collection filter by entity_id desc

Step1: Load customer collection with sort by entity descending and by using setpagesize limt collection limit 1

$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')
        ->addAttributeToSort('entity_id','desc')->setPageSize(1);

    /* get ;last customer $object by  $lastcst */

step2: get customer object getFirstItem(); which will provide fist item collection

$lastcst=$collection->getFirstItem();

Step3: get customer email

$lastcst->getEmail();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top