Here is my code.
$user_dataaa = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('company',$row[3])->getData();
echo '<pre>';print_r($user_dataaa);echo '</pre>';
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
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();
}
}