1

Here in my collection -> Table structure is :

1,id,                mydb,table_name,INT UNSIGNED,,10,3,0
2,userid,            mydb,table_name,INT UNSIGNED,,10,5,0
3,transctionid,      mydb,table_name,TEXT,,65535,15,0
4,requesttime,       mydb,table_name,TIMESTAMP,,19,19,0
5,creditamount,      mydb,table_name,SMALLINT,,5,4,0
6,creditedtime,      mydb,table_name,TIMESTAMP,,19,19,0
7,status,            mydb,table_name,SMALLINT UNSIGNED,,5,1,0

other_is_dummy_cm = is customer attribute.

In This collection I need only customer group id = 9 and other_is_dummy_cm = 0 should be in table else not

So my collection is :

$collection = Mage::getModel('user/transaction')->getCollection()
    ->addFieldToFilter('status', array('eq' => 3));
$collection->getSelect()->joinLeft(array(
    'account'=> 'campusm_account'),
    'account.userid = main_table.userid',
    array('account.accountno', 'account.ifsc', 'account.bankaddress', 'account.bankname','account.pancard_no.')
);

$firstnameAttr = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$lastnameAttr = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
// trying to put but getting error.
$dummyAttr = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'other_is_dummy_cm');

$collection->getSelect()
    ->join(array(
        'ce1' => 'customer_entity_varchar'),
        'ce1.entity_id=main_table.userid', array('firstname' => 'value')
    )
    ->where('ce1.attribute_id='.$firstnameAttr->getAttributeId()) // Attribute code for firstname.
    ->join(array(
        'ce2' => 'customer_entity_varchar'),
        'ce2.entity_id=main_table.userid', array('lastname' => 'value')
    )
    ->where('ce2.attribute_id='.$lastnameAttr->getAttributeId()) // Attribute code for lastname.
    ->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS fullname"));

0

Your Answer

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

Browse other questions tagged or ask your own question.