Magento loose table details in Google sitemap - magento

I have problems with google sitemap.
as you can see in here, I lost the detail table!...if i click add sitemap i get white page!
How can do to restore?
thank you
regards

You may have issue in "/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid.php". So check the file. Here is a code of Grid.php
class Mage_Adminhtml_Block_Sitemap_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('sitemapGrid');
$this->setDefaultSort('sitemap_id');
}
protected function _prepareCollection()
{
$collection = Mage::getModel('sitemap/sitemap')->getCollection();
/* #var $collection Mage_Sitemap_Model_Mysql4_Sitemap_Collection */
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('sitemap_id', array(
'header' => Mage::helper('sitemap')->__('ID'),
'width' => '50px',
'index' => 'sitemap_id'
));
$this->addColumn('sitemap_filename', array(
'header' => Mage::helper('sitemap')->__('Filename'),
'index' => 'sitemap_filename'
));
$this->addColumn('sitemap_path', array(
'header' => Mage::helper('sitemap')->__('Path'),
'index' => 'sitemap_path'
));
$this->addColumn('link', array(
'header' => Mage::helper('sitemap')->__('Link for Google'),
'index' => 'concat(sitemap_path, sitemap_filename)',
'renderer' => 'adminhtml/sitemap_grid_renderer_link',
));
$this->addColumn('sitemap_time', array(
'header' => Mage::helper('sitemap')->__('Last Time Generated'),
'width' => '150px',
'index' => 'sitemap_time',
'type' => 'datetime',
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sitemap')->__('Store View'),
'index' => 'store_id',
'type' => 'store',
));
}
$this->addColumn('action', array(
'header' => Mage::helper('sitemap')->__('Action'),
'filter' => false,
'sortable' => false,
'width' => '100',
'renderer' => 'adminhtml/sitemap_grid_renderer_action'
));
return parent::_prepareColumns();
}
/**
* Row click url
*
* #return string
*/
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('sitemap_id' => $row->getId()));
}
}

Related

Add multiple tabs and forms in backend of a custom module in magento just like customer backend porsitions

I have created a custom extension just like a customer module and I want backend just like a customer.
My extension has two tables and two models.
My modules are:
Mage::getModel('custommod/reg') - just like Mage::getModel('customer/customer'), reg saves data of registration
Mage::getModel('custommod/personal') - just like Mage::getModel('customer/address'), //personal data of a reg records.
Please check the image below:
Now I am facing the problem to show the data and edit .
In Magento customer admin section, Customer edit position has multiple tabs: Account information, Address etc.
Here, Account information tab saves data in customer/customer
and Address information tab saves data in customer/address.
I like this type of section.
After a long time work i have done it ,Here the solution
The tabs.php show left panel
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('vendor_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('vendor')->__('Manage Vendor'));
}
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => Mage::helper('vendor')->__('General Information'),
'title' => Mage::helper('vendor')->__('General Information'),
'content' => $this->getLayout()->createBlock('vendor/adminhtml_list_edit_tab_form')->toHtml(),
));
$this->addTab('vendor_details',array(
'label'=>Mage::helper('vendor')->__('Vendor Store Details'),
'title'=>Mage::helper('vendor')->__('Vendor Store Details'),
'content'=>$this->getLayout()->createBlock('vendor/adminhtml_list_edit_tab_storedetails')->toHtml(),
));
return parent::_beforeToHtml();
}
}
after the form.php
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$vendor = Mage::registry('vendor_data');
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('vendor_form', array(
'legend' => Mage::helper('vendor')->__('Vendor Registration')
));
$fieldset->addField('name', 'text', array(
'name' => 'name',
'label' => Mage::helper('vendor')->__('Name'),
'required' => true,
));
$fieldset->addField('email', 'text', array(
'name' => 'email',
'label' => Mage::helper('vendor')->__('Email'),
'required' => true,
));
$fieldset->addField('user_name', 'text', array(
'name' => 'user_name',
'label' => Mage::helper('vendor')->__('User name'),
'required' => true,
));
$fieldset->addField('password', 'password', array(
'name' => 'password',
'class' => 'required-entry',
'label' => Mage::helper('vendor')->__('Password'),
'required' => true,
));
$this->setForm($form);
$form->setValues($vendor->getData());
return parent::_prepareForm();
}
public function filter($value)
{
return number_format($value, 2);
}
}
Second form Storedetails.php
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tab_Storedetails extends Mage_Adminhtml_Block_Widget_Form{
protected function _prepareForm(){
$vendorStore = Mage::registry('vendor_store_details');// new registry for different module
$form = new Varien_Data_Form();
//$form->setFieldNameSuffix('vendor_store');
$fieldset = $form->addFieldset('vendor_form', array(
'legend' => Mage::helper('vendor')->__('Vendor deatsilsn')
));
$fieldset->addField('alternative_email','text',array(
'name' =>'alternative_email',
'label' => Mage::helper('vendor')->__('Alternative Email'),
'required'=> false
));
$fieldset->addField('shopname','text',array(
'name' =>'shopname',
'label' => Mage::helper('vendor')->__('Shop Name'),
'required'=> true,
'class' => 'required-entry',
));
$fieldset->addField('company', 'text', array(
'name' => 'company',
'label' => Mage::helper('vendor')->__('Company'),
'required' => true,
'class' => 'required-entry',
));
$fieldset->addField('street','text',array(
'name' =>'vendor_details[street]',
'label' => Mage::helper('vendor')->__('Street Address'),
'required'=> false
));
$this->setForm($form);
$form->addValues($vendorStore->getData());
return parent::_prepareForm();
}
}

Extending sales order Grid breaking Pagination

I am trying to extend the sales-> order Grid by Sku and product name.
I managed to get the sku and name in the Grid with all the data.
Now the problem is it's breaking the pagination.
Can anyone please help me with that.
Code:
class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('sales_order_grid');
$this->setUseAjax(true);
$this->setDefaultSort('created_at');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
/**
* Retrieve collection class
*
* #return string
*/
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
protected function _prepareCollection()
{
// Custom code
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'sku' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
'name' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
)
);
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
// Custom code
$this->addColumn('name', array(
'header' => Mage::helper('Sales')->__('Name'),
'width' => '100px',
'index' => 'name',
'type' => 'text',
));
$this->addColumn('sku', array(
'header' => Mage::helper('Sales')->__('Sku'),
'width' => '100px',
'index' => 'sku',
'type' => 'text',
));
$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sales')->__('Purchased From (Store)'),
'index' => 'store_id',
'type' => 'store',
'store_view'=> true,
'display_deleted' => true,
));
}
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'type' => 'datetime',
'width' => '100px',
));
$this->addColumn('billing_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 'billing_name',
));
$this->addColumn('shipping_name', array(
'header' => Mage::helper('sales')->__('Ship to Name'),
'index' => 'shipping_name',
));
$this->addColumn('base_grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Base)'),
'index' => 'base_grand_total',
'type' => 'currency',
'currency' => 'base_currency_code',
));
$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
'index' => 'grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));
$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
$this->addColumn('action',
array(
'header' => Mage::helper('sales')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('View'),
'url' => array('base'=>'*/sales_order/view'),
'field' => 'order_id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
}
$this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));
$this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
$this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
return parent::_prepareColumns();
}
Problem is with my Collection. I am working here with core class but I will override it once I get my result.
You have a GROUP BY clause in your collection, and the grid pager uses $collection->getSize() to determine the number of pages. The problem is that getSize() applies a SELECT COUNT(*) to the collection, and fetches the first column of the first row to get the number of results. With the GROUP BY still applied, the pager then considers that there is only one result.
To prevent this problem, you should either use your own orders collection with a relevant getSize(), or use sub-queries to retrieve SKUs and names.

add tab in admin dashboard magento 1.7.0.2

Copy Ordered.php
From
app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products
to
app/code/local/Mage/Adminhtml/Block/Dashboard/Tab/Products
Rename New.php
I have modified the following code:
class Mage_Adminhtml_Block_Dashboard_Tab_Products_New extends Mage_Adminhtml_Block_Dashboard_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('productsNewGrid');
}
protected function _prepareCollection()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_Sales')) {
return $this;
}
if ($this->getParam('website')) {
$storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds();
$storeId = array_pop($storeIds);
} else if ($this->getParam('group')) {
$storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds();
$storeId = array_pop($storeIds);
} else {
$storeId = (int)$this->getParam('store');
}
$todayStartOfDayDate = Mage::app()->getLocale()->date()
->setTime('00:00:00')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$todayEndOfDayDate = Mage::app()->getLocale()->date()
->setTime('23:59:59')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $todayEndOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayStartOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter(
array(
array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
)
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('name', array(
'header' => $this->__('Product Name'),
'sortable' => false,
'index' => 'product_name'
));
$this->addColumn('price', array(
'header' => $this->__('Price'),
'width' => '120px',
'type' => 'currency',
'currency_code' => (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode(),
'sortable' => false,
'index' => 'product_price'
));
$this->addColumn('ordered_qty', array(
'header' => $this->__('Quantity Ordered'),
'width' => '120px',
'align' => 'right',
'sortable' => false,
'index' => 'qty_ordered',
'type' => 'number'
));
$this->setFilterVisibility(false);
$this->setPagerVisibility(false);
return parent::_prepareColumns();
}
/*
* Returns row url to show in admin dashboard
* $row is bestseller row wrapped in Product model
*
* #param Mage_Catalog_Model_Product $row
*
* #return string
*/
public function getRowUrl($row)
{
// getId() would return id of bestseller row, and product id we get by getProductId()
$productId = $row->getProductId();
// No url is possible for non-existing products
if (!$productId) {
return '';
}
$params = array('id' => $productId);
if ($this->getRequest()->getParam('store')) {
$params['store'] = $this->getRequest()->getParam('store');
}
return $this->getUrl('*/catalog_product/edit', $params);
}
}
Then Copy Grids.php
From
app/code/core/Mage/Adminhtml/Block/Dashboard/
to
app/code/local/Mage/Adminhtml/Block/Dashboard/
added the following code:
$this->addTab('new_products', array(
'label' => $this->__('New Product'),
'content' => $this->getLayout()->createBlock('adminhtml/dashboard_tab_products_new')->toHtml(),
'class' => 'ajax'
));
I want to add a new product tab in admin dashboard,beside customers.I don't know what wrong with the New.php.I click the new product tab,it's not working.How to fix it?
I have managed to get this working with only a few more lines to change.
Update the Dashboard controller Mage_Adminhtml_DashboardController to add the new action
public function productsNewAction()
{
$this->loadLayout();
$this->renderLayout();
}
Update the admin layout.xml design\adminhtml\default\default\layout\main.xml to add the new section
<adminhtml_dashboard_productsnew>
<block type="core/text_list" name="root" output="toHtml">
<block type="adminhtml/dashboard_tab_products_new" name="adminhtml.dashboard.tab.products.new"/>
</block>
</adminhtml_dashboard_productsnew>
The you would just need to update your code in the Grids.php to the following.
$this->addTab('new_products', array(
'label' => $this->__('New Product'),
'url' => $this->getUrl('*/*/productsNew', array('_current'=>true)),
'class' => 'ajax'
));
This should then work using a call to the url rather than the block content.
You then need to select the attributes you want to show. You can do this by selecting all or by attribute code.
$collection->addAttributeToSelect('*')
$collection->addAttributeToSelect('name');
Important is the column index defined in _prepareColumns match these attribute codes Otherwise you will just get an empty row.
I would suggest packaging these changes into a new module with a controller, layout.xml and block files. There are lots of great tutorials around on how to do this, but obviously you don't have to :)

magento tabbed backend like catalog/product for custom entity

I want to write a module with a custom entity. In the backend it shall look like the backend from products (tabs on the left, forms on the right).
I tried many variants and inspected/copied many things from the core to understand it... well I don't.
Knows anyone a tutorial or the neccessary key points to realize this?
Many thanks
Edit: well, it's not the problem to create own entities, this is well known.
I need help to create the backend, so that the result looks like the tabbed form when editting products
For adding multiple tabs in admin first go through the http://codemagento.com/2011/02/grids-and-forms-in-the-admin-panel/ provided by mpaepper.
after that create below class
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_Form
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_SecondTab
and modify the
Super_Awesome_Block_Adminhtml_Example_Edit_Form to
class Super_Awesome_Block_Adminhtml_Example_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data',
));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Add below code
class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
public function __construct() {
parent::__construct();
$this->setId('awesome_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('awesome')->__('Your Title Here'));
}
protected function _beforeToHtml() {
$this->addTab('form_section', array(
'label' => Mage::helper('awesome')->__('Details'),
'title' => Mage::helper('awesome')->__('Details'),
'content' => $this->getLayout()->createBlock('awesome/adminhtml_awesome_edit_tab_form')->toHtml(),
));
$this->addTab('secondtab_section', array(
'label' => Mage::helper('awesome')->__('SecondTab'),
'title' => Mage::helper('awesome')->__('SecondTab'),
'content' => $this->getLayout()->createBlock('awesome/adminhtml_awesome_edit_tab_secondtab')->toHtml(),
));
return parent::_beforeToHtml();
}
}
...
class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('awesome_form', array('legend'=>Mage::helper('awesome')->__('Header text here')));
$fieldset = $form->addFieldset('example_form', array(
'legend' =>Mage::helper('awesome')->__('Example Information')
));
$fieldset->addField('name', 'text', array(
'label' => Mage::helper('awesome')->__('Name'),
'class' => 'required-entry',
'required' => true,
'name' => 'name',
'note' => Mage::helper('awesome')->__('The name of the example.'),
));
$fieldset->addField('description', 'text', array(
'label' => Mage::helper('awesome')->__('Description'),
'class' => 'required-entry',
'required' => true,
'name' => 'description',
));
$fieldset->addField('other', 'text', array(
'label' => Mage::helper('awesome')->__('Other'),
'class' => 'required-entry',
'required' => true,
'name' => 'other',
));
if (Mage::getSingleton('adminhtml/session')->getExampleData())
{
$data = Mage::getSingleton('adminhtml/session')->getExamplelData();
Mage::getSingleton('adminhtml/session')->getExampleData(null);
}
elseif (Mage::registry('example_data'))
{
$data = Mage::registry('example_data')->getData();
}
else
{
$data = array();
}
return parent::_prepareForm();
}
}
....
class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_SecondTab extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setId('awesomeGrid');
$this->setDefaultSort('awesome_secondtab_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setFilterVisibility(false);
$this->setPagerVisibility(false);
}
protected function _prepareCollection() {
$id = $this->getRequest()->getParam('id');
$collection = Mage::getModel('awesome/secondtab')->getCollection()->addFilter('awesome_id', $id);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('created_time', array(
'header' => Mage::helper('awesome')->__('Date'),
'index' => 'created_time',
'type' => 'datetime',
'align' => 'left',
'sortable' => false,
));
$this->addColumn('type', array(
'header' => Mage::helper('awesome')->__('Type'),
'align' => 'left',
'index' => 'type',
'sortable' => false,
));
$this->addColumn('amount', array(
'header' => Mage::helper('awesome')->__('Amount'),
'align' => 'left',
'index' => 'amount',
'type' => 'currency',
'currency' => 'amount',
'sortable' => false,
));
$this->addColumn('balance', array(
'header' => Mage::helper('awesome')->__('Balance'),
'align' => 'left',
'index' => 'balance',
'type' => 'currency',
'currency' => 'balance',
'sortable' => false,
));
$this->addColumn('order_number', array(
'header' => Mage::helper('awesome')->__('Order Number'),
'align' => 'left',
'index' => 'order_number',
'sortable' => false,
));
return parent::_prepareColumns();
}
}

Add a dropdown attribute in Product report grid Magento

I'm trying to add new product attributes to Reports->Products Ordered grid. I copied the /app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php to
/app/code/local/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php and add attributes like this:
protected function _prepareColumns()
{
$this->addColumn('created_at', array(
'header' =>Mage::helper('reports')->__('Create At'),
'index' =>'created_at'
));
$this->addColumn('sku', array(
'header' =>Mage::helper('reports')->__('sku'),
'index' =>'sku'
));
$this->addColumn('name', array(
'header' =>Mage::helper('reports')->__('Product Name'),
'index' =>'name'
));
$this->addColumn('color', array(
'header' =>Mage::helper('reports')->__('Color'),
'index' =>'color',
'type' => 'options'
));
$this->addColumn('size', array(
'header' =>Mage::helper('reports')->__('Size'),
'index' =>'size'
));
$this->addColumn('price', array(
'header' =>Mage::helper('reports')->__('Price'),
'width' =>'120px',
'type' =>'currency',
'currency_code' => $this->getCurrentCurrencyCode(),
'index' =>'price'
));
$this->addColumn('ordered_qty', array(
'header' =>Mage::helper('reports')->__('Quantity Ordered'),
'width' =>'120px',
'align' =>'right',
'index' =>'ordered_qty',
'total' =>'sum',
'type' =>'number'
));
$this->addExportType('*/*/exportSoldCsv', Mage::helper('reports')->__('CSV'));
$this->addExportType('*/*/exportSoldExcel', Mage::helper('reports')->__('Excel'));
return parent::_prepareColumns();
}
Problem is, 'Color' and 'Size' are dropdown attributes thats why they are showing the option values instead of option text. How to show the Text value for dropdown attributes in grid?
EDIT 1
Thanks BOOMER... I have changed my Grid.php as you suggested and it showing the blank color column now. Heres what I did:
protected function _prepareCollection()
{
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('color');
parent::_prepareCollection();
$this->getCollection()
->initReport('reports/product_sold_collection');
return $this;
}
/**
* Prepare Grid columns
*
* #return Mage_Adminhtml_Block_Report_Product_Sold_Grid
*/
protected function _prepareColumns()
{
$colors = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter(80) // set your attribute ID here
->setStoreFilter()
->load()
->toOptionHash('option_id', 'value');
$this->addColumn('created_at', array(
'header' =>Mage::helper('reports')->__('Create At'),
'index' =>'created_at'
));
$this->addColumn('sku', array(
'header' =>Mage::helper('reports')->__('sku'),
'index' =>'sku'
));
$this->addColumn('name', array(
'header' =>Mage::helper('reports')->__('Product Name'),
'index' =>'name'
));
$this->addColumn('color', array(
'header' =>Mage::helper('reports')->__('Color'),
'index' =>'color',
'type' => 'options',
'options' => $colors
));
}
First ensure you are adding the attribute to select in your _prepareCollection() method, for example:
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('color');
And within your _prepareColumns() you'll need to define the collection of options to use:
$colors = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter(15) // set your attribute ID here
->setStoreFilter()
->load()
->toOptionHash('option_id', 'value');
Be sure and set the attribute ID accordingly. Then use this collection list in your addColumns like so:
$this->addColumn('color', array(
'header' =>Mage::helper('reports')->__('Color'),
'index' =>'color',
'type' => 'options',
'options' => $colors
));
Hope this helps!
I would suggest you to use a different approach, at least for custom attributes. Try replacing your $colors = actions with the following
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
$colors = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
$colors[$option['value']] = $option['label'];
}
I usually replace the statement inside the foreach with an if condition to avoid duplicate blank options, i.e.:
if ($option['label'])
$sets[$option['value']] = $option['label'];

Resources