Question

I'm creating a custom module for a specific function in the admin of Magento. Within the Adminhtml grid, I am pulling in line order items, but also need to pull in data specific to each product as it currently stands in the database.

Attached is the screenshot of my current Adminhtml grid. Adminhtml Grid I need to add product attributes (brand, flavor, etc.) as additional columns to the grid. How would I go about doing this? I tried adding a

$collection->join()

on the

_prepareCollection()

function, but could not figure out which exact tables to join on (flat indexing is turned on).

Thanks! Mark


Thanks for the tip. Not exactly what I was looking for as I'm dealing with EAV objects with select menus, but it is close (upvoting).

Here are the collection selects I'm going to wind up adding in:

$collection->getSelect()->join('catalog_product_index_eav', '`catalog_product_index_eav`.`entity_id` = `main_table`.`product_id` AND `catalog_product_index_eav`.`attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = "brand")', array('attribute_id'));
$collection->getSelect()->join('eav_attribute_option_value', '`eav_attribute_option_value`.`option_id` = `catalog_product_index_eav`.`value`', array('brand' => 'value'));

I don't really need the search functionality in the input text box of this new Brand column, however does anyone know how to make this work? Receiving this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'brand' in 'where clause'

I can go in and diagnose, but figured someone might know off the top of their head.

Was it helpful?

Solution

You're going to have to figure out the tables to use in the join.

$collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id AND `sales_flat_order_item`.parent_item_id IS NULL  ', null);

$collection->getSelect()->join('catalog_product_entity_varchar', '`catalog_product_entity_varchar`.attribute_id=144 AND `catalog_product_entity_varchar`.entity_id = `sales_flat_order_item`.`product_id`', array('models'  => new Zend_Db_Expr('group_concat(`catalog_product_entity_varchar`.value SEPARATOR ",")')))

Source: http://www.atwix.com/magento/customize-orders-grid/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top