Skip to main content
added 286 characters in body
Source Link
Raul Sanchez
  • 3.2k
  • 3
  • 29
  • 65

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

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

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

$customers$customerAddresses->addFieldToFilter>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

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

$customers = Mage::getModel('customer/customer')->getCollection();
$customers->addFieldToFilter('company', array('like' => '%' . $company . '%'));
foreach ($customers as $customer){
    print_r($customer->getId());
}

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

$customers->addFieldToFilter('company', array('eq' => $company));

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

Source Link
Raul Sanchez
  • 3.2k
  • 3
  • 29
  • 65

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

$customers = Mage::getModel('customer/customer')->getCollection();
$customers->addFieldToFilter('company', array('like' => '%' . $company . '%'));
foreach ($customers as $customer){
    print_r($customer->getId());
}

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

$customers->addFieldToFilter('company', array('eq' => $company));