Goto app/code/core/Mage/Page/Block/Template/Links.php
copy to app/code/local/Mage/Page/Block/Template/Links.php
then goto addLink() function goto
$link = new Varien_Object(array(
add below code
if($label=='My Account'):
$loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
if( $loggedIn){
$label=Mage::getSingleton('customer/session')->getCustomer()->getName();
}
endif;
and My Account
depend on xml code <label>My Account</label>
Try this
Step1: trigger an event on basic of customer_save_before
<global>
<events>
<customer_save_before>
<observers>
<stockalert>
<type>singleton</type>
<class>magento37890/observer</class>
<method>checkDisplay</method>
</stockalert>
</observers>
</customer_save_before>
</events>
</global>
Step2:
In before event
give you can get customer id
if customer is old
,then checking current value and past value match or not
.
If not match then checking this value exit in Rest of collection
. If exit then send a flag (false)
and
throw error using throw Mage::exception
which prevent data save
.....
if($flagofmy==false){
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('This customer lastname already exists'),
Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
);
}
full Logic
<?php
class Stackexchange_Magento37890_Model_Observer
{
public function checkDisplay(Varien_Event_Observer $observer){
$flagofmy=true;
//eeeeee
$customer=$observer->getEvent()->getCustomer();
Mage::log('My log entry'.$customer->getId(), null, 'Magento37890.log');
/* if customer is old customer */
if($customer->getId()){
if($customer->getOrigData('lastname')!=$customer->getData('lastname')){
Mage::log($customer->getData('lastname').'My log entry'.$customer->getId(), null, 'Magento37890.log');
$flagofmy=$this->HasLastName($customer->getData('lastname'));
if($flagofmy==false){
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('This customer lastname already exists'),
Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
);
}
}else{
Mage::log($customer->getData('lastname').' Step A _1'.$customer->getId(), null, 'Magento37890.log');
}
}else{
/* New Customer */
$flagofmy=$this->NewHasLastName($customer->getData('lastname'));
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('This customer lastname already exists'),
Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
);
}
}
protected function HasLastName($lastname){
$customer_check = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('lastname')
->addAttributeToFilter('lastname',$lastname);
if(count($customer_check)>0){
return false;
}
return true;
}
}
Note: I have done basic of lastname field juts need to change field name to display_name
Best Answer
Alternatively you can try this, if you have the customer's email address:
Or if you have customer ID then you can directly check in
newsletter_subscriber
table to check if customer ID exists or not.