6

I want to load customer and get his data from telephone number we have load() methods, to load customer by id as well as we have loadByEmail() to load customer by Email but i want to load customer by providing his telephone number and get his data.

  • Thanks But i have gone through that answer earlier but that dint seemed to helped me Thus i asked for it :) – Shashank Jun 27 '16 at 11:21
  • Then you should mention it in the question: what did you try? what happened? As it stands, the exact question has been asked before and you would not get a different answer. – Fabian Schmengler Jun 27 '16 at 11:28
  • Yes but i am that much not familier about it Sorry for that and Thanks – Shashank Jun 27 '16 at 11:30
1

If you take a look at load function the second parameter is the field to load, by default entity_id

Your need is $customer = Mage::getModel('customer/customer')->load('123456', 'phone_number_attribute_code');

/**
 * Load object data
 *
 * @param   integer $id
 * @return  Mage_Core_Model_Abstract
 */
public function load($id, $field=null)
{
    $this->_beforeLoad($id, $field);
    $this->_getResource()->load($this, $id, $field);
    $this->_afterLoad();
    $this->setOrigData();
    $this->_hasDataChanges = false;
    return $this;
}
| improve this answer | |
3

You can search by below code, you can set your attribute value instead of telephone:

$telephone = '32423423';

$result = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('telephone', $telephone) //replace your attribute of mobile
    ->load();

if (is_object($result)) {
    //set your code...
}
| improve this answer | |
  • Fatal error: Uncaught Error: Call to a member function getBackend() on boolean in \Mage\Eav\Model\Entity\Abstract.php:816 Stack trace: #0 Mage\Eav\Model\Entity\Collection\Abstract.php(1377): Mage_Eav_Model_Entity_Abstract->isAttributeStatic('telephone') #1 \app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(321): Mage_Eav_Model_Entity_Collection_Abstract->_getAttributeConditionSql('telephone', '123456', 'inner') #2 \cust.php(30): Mage_Eav_Model_Entity_Collection_Abstract->addAttributeToFilter('telephone', '7838183888') #3 {main} thrown in Mage\Eav\Model\Entity\Abstract.php on line 816 – Shashank Jun 27 '16 at 10:41
  • I have tried your solution but got the above error :( can you please help me out what am i doing wrong? – Shashank Jun 27 '16 at 10:42
2

At magento telephone is Customer address attribute.

If you want to get Customer details from telephone then you need to check Customer Id from Mage::getModel('customer/address') model.

    $CustomAddress=Mage::getModel('customer/address')->getCollection()->addAttributeToFilter('telephone',$YourValue)->getFirstItem();

    $customerId= $CustomAddress->getCustomerId($CustomAddress);

Then using Customer id,You can get Custome data by load Customer model

$customer = Mage::getModel(‘customer/customer’)->load($customerId);
| improve this answer | |
  • I have tried your solution but got the following error Fatal error: Uncaught Error: Call to undefined method Mage_Customer_Model_Resource_Address_Collection::getFirstIem() in D:\xampp\htdocs\magento\cust.php:25 Stack trace: #0 {main} thrown in D:\xampp\htdocs\magento\cust.php on line 25 can you please help me out if i am doing something wrong?? – Shashank Jun 27 '16 at 10:45
  • getFirstIem should be getFirstItem – Amit Bera Jun 27 '16 at 10:46
  • still i am not able to get all the data i am just getting the customer created date time... well i will have a look at it again :) Thanks for the help :D – Shashank Jun 27 '16 at 11:11
  • I will check and get back to ypu – Amit Bera Jun 27 '16 at 11:12

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