0

Here is my code.

 $user_dataaa = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('company',$row[3])->getData();
 echo '<pre>';print_r($user_dataaa);echo '</pre>';
0

2 Answers 2

0

You assume company is unique? I am not sure about that, if that's not the case you can try something like this, while $company is the company name

$customerAddresses = Mage::getModel('customer/address')->getCollection();
$customerAddresses->addAttributeToSelect('company');
$customerAddresses->addAttributeToFilter('company', array('like' => '%' . $company . '%'));
foreach ($customerAddresses as $customerAddress){
    print_r($customerAddress->getCustomerId());
}

You can change the like statement for an equal if you are sure $company contains the exact value

$customerAddresses->addAttributeToFilter('company', array('eq' => $company));

UPDATE

My mistake, as company is a customer address attribute, not a direct customer attribute. Check above updated code, you'd consider sometimes customer_id could be null, if address is not associated to any customer

4
  • thanks for answer.I know company name is not unique but i have only company name to get the details of the customers.
    – devil
    Commented Jan 5, 2018 at 12:38
  • and now i got this error after using your code => Invalid attribute name: company
    – devil
    Commented Jan 5, 2018 at 12:40
  • I have edited the answer Commented Jan 5, 2018 at 12:48
  • Its Working....You Rocks man :)
    – devil
    Commented Jan 5, 2018 at 12:54
0

Try this:

Get first customer id:

$companyName = "CCC";
$collection = Mage::getModel('customer/address')->getCollection()
    ->addAttributeToSelect('company')
    ->addAttributeToFilter('company', array('eq' => $companyName));

if($collection->getSize()) {
    $address = $collection->getFirstItem();
    echo $address->getCustomerId();

}

OR

Get all customers id:

$companyName = "CCC";
$collection = Mage::getModel('customer/address')->getCollection()
    ->addAttributeToSelect('company')
    ->addAttributeToFilter('company', array('eq' => $companyName));

if($collection->getSize()) {
    foreach($collection as $address) {
        echo $address->getCustomerId();    
    }   
}
2
  • i got this error "Invalid attribute name: company".
    – devil
    Commented Jan 5, 2018 at 12:35
  • update ans pls check now
    – Abdul
    Commented Jan 5, 2018 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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