0

I've just managed to include a custom customer attribute in the order grid columns like this:

$agenteAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'agente');
$agenteTable = $agenteAttribute->getBackendTable();
$agenteId = $agenteAttribute->getAttributeId();
$collection->getSelect()->joinLeft(
    array('ca' => $agenteTable),
    'ca.attribute_id='.$agenteId.' AND ca.entity_id =main_table.customer_id',
    array('agente'  => new Zend_Db_Expr('ca.value')
    )
);

But when I try to search in the filter field of the order grid, I get this log error:

Unknown column 'agente' in 'where clause', query was: SELECT COUNT(*) FROM sales_flat_order_grid AS main_table WHERE (agente LIKE '%312%')";i:1;s:5885:"#0

I tried these two functions but without success:

$collection->addFieldToFilter('agente',array('in' => array(313)));
$this->setDefaultFilter(array('agente'=>312));

How can I do? Thanks for any help

0

FIND SOLUTION! I hope this can serve someone else: In app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php i inserted this code in _prepareCollection():

protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass());

$agenteAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'agente'); $agenteTable = $agenteAttribute->getBackendTable(); $agenteId = $agenteAttribute->getAttributeId();

$collection->getSelect()->joinLeft(
    array('ca' => $agenteTable),
    'ca.attribute_id='.$agenteId.' AND ca.entity_id = main_table.customer_id',
    array('agente'  => new Zend_Db_Expr('ca.value')
    )
);

$collection->addFilterToMap("agente","ca.value");

$collection->addFieldToFilter('agente', array('in', attribute_value));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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