Question

I'm redoing an existing shop in Magento, the client is requesting that when customers register, their customer number gets set to their mobile number (which is required, and asked for at registration). Now I personally don't think this is good practice, but it's something they're set on having. I'm looking into a proper way to do this. I am not quite sure what to override or where to start, as I've never altered registration before.

Is this possible? And if so, could you help point me in the right direction on how to accomplish this.

Was it helpful?

Solution

It looks like you mean the entity_id with "customer number", if so: No, this isn't possible in a reasonable way. However, there is the field increment_id which is meant to be used for customer numbers and can contain custom logic.

By default, it is not used at all, but you can activate it in System > Configuration > Customer Configuration > Create New Account Options > Generate Human-Friendly Customer ID

Then it uses an increment model, similar to order numbers. You can define your own increment models as described here but in your case you will need to set the value directly in an observer and not activate the abovementioned setting, because the value depends on other attributes and not on the previous number.

So, write an observer vor customer_save_before like this

public function setCustomerNumber(Varien_Event_Observer $observer)
{
    $observer->getCustomer()->setIncrementId($observer->getCustomer()->getMobileNumber());
}

OTHER TIPS

I would highly advise against editing the entity_id in MySQL.

You should create a new attribute that is unique for the customer phone number. You can then add this number to the admin grid so your client can see it.

This is the scenario that can happen:

A customer is given the ID of a phone - That id is also the database key Two years pass by and the customer has since left their company and their phone number is old and is re-issued.

A new customer signs up with the same phone number and they can't because the number already exists.

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