How to find customers with attributes and user defined attributes in Magento?

In Magento, Customer model has an option addAttributeToFilter which helps to filter customers by attributes. For example, If We would like to get customers collections with group_id(Customer group) 3, we can use as following

$customers  = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('group_id', array('eq' => 123123))
    ->load();

for user defined attribute is also same. Here customer_number is user-defined attribute:

$customers  = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('customer_number', array('eq' => 123123))
    ->load();

Multiple attributes also can used with “AND” Condition

$customers  = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('customer_number', array('eq' => 123123))
    ->addAttributeToFilter('group_id', array('eq' => 3))
    ->load();

Following work for OR condtion for two attributes:

$customers  = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter(
   array(
     array('customer_number', array('eq' => 123123))
     array('group_id', array('eq' => 3))
    )
    ->load();

For individual afterwards:

foreach ($customers as $customer)
{
   var_dump($customer->getData());
}

If the attribute is unique value then We can directly get Row:

$customer  = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('customer_number', array('eq' => 123123))
    ->addAttributeToFilter('group_id', array('eq' => 3))
    ->load()
    ->getFirstItem();

Finally, If we need only selected attributes like firstname, lastname and email:

$customers  = Mage::getModel('customer/customer')
   ->getCollection()
   ->addAttributeToSelect('firstname')
   ->addAttributeToSelect('lastname')
   ->addAttributeToSelect('email');
   ->addAttributeToFilter('group_id', array('eq' => 3))
   ->load();

OroCRM: Fatal error: Uncaught exception ‘RuntimeException’ with message ‘The php executable could not be found, add it to your PATH environment variable and try again’

It is very common error in OROCRM “The PHP executable not found” :

Fatal error: Uncaught exception ‘RuntimeException’ with message ‘The php executable could not be found, add it to your PATH environment variable and try again’

It can be fixed by changing to Production environment from development. Following line at web/app.php

$kernel = new AppKernel('prod', false);

to

$kernel = new AppKernel('prod', true);

 

Magento/PHP create new session every refresh

I had problem with php session. When I reload the page it create new session ID.  Finally I fixed the problem. If you did not set the session.save_path by default it will be like


session.save_path="/tmp/"

in php.ini. change this to


session.save_path=/tmp

without quote(“”) sign.
 

eXTReMe Tracker