0

I have a client which uses a ERP System to handle all Magento orders. For this reason I have created a module which exports all orders as a csv file. In Addition the ERP System of my client expect a continuous customer id, but the problem is that only registered customers get a customer id, so guests don't have a customer id, but customers ids should be continuous like the following example:

40000,               40001, 40002, 40003
registered customer, guest, guest, registed customer

Is there a way in Magento to grab the last customer id and add the guest temporary as new customer, so that Magento get notice of the new last customer id and remove this temporary customer after this action again?

I am looking for something like the following pseudocode:

$lastCustomerId = $customerCollection->getLastId();
$newId = $lastCustomerId + 1;
$customer = Mage::getModel("customer/customer");
$customer->setId($newId);
$customer->save();

// write the id to the file

$customer = Mage::getModel('customer/customer')->load($newId);
$customer->delete();
0

Ok this works for me:

if ($order->getCustomerId() === null) {
    $websiteId = Mage::app()->getWebsite()->getId();
    $store = Mage::app()->getStore();
    $tempCustomer = Mage::getModel("customer/customer");
    $tempCustomer->setWebsiteId($websiteId)
        ->setStore($store)
        ->setFirstname('temporary')
        ->setLastname('temporary')
        ->setEmail('temp@muster.de')
        ->setPassword('temporary');

    $tempCustomer->save();

    $customers = Mage::getModel('customer/customer')->getCollection();
    $customerId = $customers->getLastItem()->getId();

    Mage::register('isSecureArea', true);
    $tempCustomer = Mage::getModel('customer/customer')->load($customerId);
    $tempCustomer->delete();
    Mage::unregister('isSecureArea');
}

So the continuous customer id is stored in $customerId.

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.