I am trying to add custom columns to the product grid within the Adminhtml module. I want to add columns that display custom product attributes and obviously filter the product grid by those attribute values.
I have an attribute called “classification” . I have been able to add the custom column to the grid, but no values are displayed in the column (see image 1) although the filter is working good (see image 2).
And here the snippet of code for the grid: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php. I have first add to the collection : ->addAttributeToSelect(’classification’) :
You are right : it works! Your observation give me a way.
In fact I had created a local module :
1 - edit my own : /app/code/local/Mymodule/Adminhtlm/Block/catalog/Product/Grid.php
2 - replace class definition in Grid.php by : Class Mymodule_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
3 - create : /app/etc/modules/Mymodule.xml and /app/etc/local.xml
And the result is as describe in my first post.
So what I have done after your response is to put the code in app/code/local/Mage/Adminhtlm/Block/catalog/Product/Grid.php (with the original class defintion) and eveythings work now.
I am not a developper and I don’t know how to do this with a custom module. Do you have an idea?
Wanted to achieve the same purposed for Admin>Sales>Order, where i wanted to add additional attribute “Delivery Date” which i’d managed to add in along with every orders made.
I’d managed to add the column from the ...Adminhtml\Block\Sales\Order\grid.php, and i managed to find out the php file that fletch the order records to display at Admin>Sales>Order is .....Adminhtml\Block\widget\grid.php..but the code is different from cooper where i can just simpley add in ‘addAttributeToSelct(’delivery_date’) where this attribute is stored in gift_message table.
ok i don’t know if this will help you all at all.... but i needed to haxor a freaking manufacturer column for my client. i was totally successful in getting the data to display in the admin view (ROX!!!!), but the values were just the integers of the manufacturer id, not the title.
manufacturer is attribute_id=55 in the database
then i was getting the correct option_id’s (which were a collection related to attribute_id=55
i needed to grab the values of the plain text label associated with the option id (for all stores too)
this is a little sloppy as i haven’t abstracted anything out into its own module here.
here is the scariest part (but my roommate doesn’t really care about magento so, he was like, well this will work, if it breaks other stuff its on you.... so again beware…
/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php
around line 96.
// Modded to allow fieldnames to pass in. public function toOptionHash($valueField='id', $labelField='name') { return $this->_toOptionHash($valueField, $labelField); }
this is working for me… hopefully its helpful for you all.
remember this ain’t gwana’ work unless you got the Manufacture attribute going on.
I stumbled across this post by accident, and found it very interesting. Ofcourse one has to be able to do selecting by custom attributes in the backend,
Anyway:
Got this working fine for me with a custom selectattribute.
But: I am trying to get this to work for an other attribute where one can choose multiple options.
And guess what? It does not work.
I got the options shown in the collumn header but they won’t show up in the grid itself. Filtering with this option returns zero products.
some code:
->addAttributeToSelect('Druif') // this one is fine. It's a select input type ->addAttributeToSelect('Smaak')// this one not working it's a multiselect
I noticed that in the eav_entity table the attrubutes with multiple select have
a “eav/entity_attribute_backend_array” value in their collumn “backend_model” and the normal select has nothing in it
I looked at the visibilty collumn because there you have also multiple options like “Catalog,Search” when both are selected; But no luck.
I tried using your example, the manufacturer field and column appearsin the admin section however neither the drop down or any of the items have the new column populated with any data. I have manufacturers associated with my products, and manufacturers appear on the front-end just fine. Any idea on what I could be missing?
/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php
around line 96.
// Modded to allow fieldnames to pass in. public function toOptionHash($valueField='id', $labelField='name') { return $this->_toOptionHash($valueField, $labelField); }
ok i don’t know if this will help you all at all.... but i needed to haxor a freaking manufacturer column for my client. i was totally successful in getting the data to display in the admin view (ROX!!!!), but the values were just the integers of the manufacturer id, not the title.
manufacturer is attribute_id=55 in the database
then i was getting the correct option_id’s (which were a collection related to attribute_id=55
i needed to grab the values of the plain text label associated with the option id (for all stores too)
this is a little sloppy as i haven’t abstracted anything out into its own module here.
here is the scariest part (but my roommate doesn’t really care about magento so, he was like, well this will work, if it breaks other stuff its on you.... so again beware…
/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php
around line 96.
// Modded to allow fieldnames to pass in. public function toOptionHash($valueField='id', $labelField='name') { return $this->_toOptionHash($valueField, $labelField); }
this is working for me… hopefully its helpful for you all.
remember this ain’t gwana’ work unless you got the Manufacture attribute going on.
check this out, maybe this can help you :
$items = Mage::getModel('eav/entity_attribute_option')->getCollection() ->setStoreFilter() ->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code'); foreach ($items as $item) : if ($item->getAttributeCode() == 'manufacturer') $x[$item->getOptionId()] = $item->getValue(); endforeach;
I am having the same issue… I have follow all the instructions and read other threads on this issue and can’t get it to work. I want to overload the class and am doing so by the manual and other threads.
I’m getting the same problem. The columns show up and if you do the drop down and provide filter, the values will show up in the grid, but if you are providing no filter, the values don’t show up in the grid.