How to select specific fields with aliases using joinTable or joinField in Magento

前端 未结 3 1268
迷失自我
迷失自我 2021-02-15 06:29

I want to pre-filter* data in the invoice grid visible in Magento\'s admin panel.

Here is a question that I asked earlier, and this one is related to the solution prese

3条回答
  •  再見小時候
    2021-02-15 07:00

    I finally did achieve this by going from invoice->order->customer as 'Anda B' suggested. I am just pasting my solution here as a reference, but will be using this solution from clockworkgeek, since it seems much cleaner. And my solution still needs to be made cleaner by getting the 'id' of eav_attribute (agent_id) from the database at runtime, instead of hard coding it, as pasted here:

    class Myproject_Adminhtml_Block_Sales_Invoice_Grid extends Mage_Adminhtml_Block_Sales_Invoice_Grid
    {
        const AGENT_ID_ATTRIBUTE_ID = 118;
    
        protected function _prepareCollection()
        {
    
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    
            $collection->join('order_grid', 'order_id = order_grid.entity_id', array ('order_entity_id' => 'order_grid.entity_id'));
            $collection->getSelect()->join( 'customer_entity', 'customer_id = customer_entity.entity_id', array('customer_entity_id' => 'entity_id', 'email'));
            $collection->getSelect()->joinLeft( 'customer_entity_int', 'customer_entity_int.entity_id = customer_entity.entity_id AND attribute_id = ' . Myproject_Adminhtml_Block_Sales_Invoice_Grid::AGENT_ID_ATTRIBUTE_ID, 
                                            array('attribute_entity_id' => 'customer_entity_int.entity_id', 'attribute_id' , 'value'));
    
    //Apply Desired Data Filters here
    
    $this->setCollection($collection);
    
    return $collection;
    

提交回复
热议问题