In Magento how to show custom attribute in product grid ..? - magento

Thanks in advance
i have made one attribute with option of yes/no i want to show this in product grid at admin side i made the column in the grid and put the following code
<?php
$this->addColumn('approvedcustomer',
array(
'header'=> Mage::helper('catalog')->__('UrgeStatus'),
'index' => 'approvedcustomer',
));
?>
here approvedcustomer is attribute and it contains option yes/no
but in grid it shows 0 and 1 how can i show Approved and Unapproved insted of 0 and 1..
sorry for my english,
thanks once again.
Jeet.

You should assign "options" type for your column.
$this->addColumn('approvedcustomer',
array(
'header'=> Mage::helper('catalog')->__('UrgeStatus'),
'index' => 'approvedcustomer',
'type' => 'options',
'options' => array(
0 => 'No',
1 => 'Yes',
)
));

Related

Not saving data when add multiple select attribute in product grid

I have created one custom module with add associated products concept. Created successfully. And Its working well.
But when i add "Multi select attribute" column in product grid with that option values, That entity value not saved.
If i removed that option values from that brand attribute drop down, Its saving fine.
I have shown my code below what i did for add multi select attribute column in product grid
under _prepareColumns() method
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand'); // attribute code here
foreach ( $attribute->getSource()->getAllOptions(true, true) as $option)
{
if($option['value'] != '')
$valArr[$option['value']] = $option['label'];
}
$this->addColumn('brand', array(
'header'=> Mage::helper('catalog')->__('Brand'),
'align' => 'left',
'index' => 'brand',
'type' => 'options',
'options' => $valArr,
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Brands', // Will have to create the renderer.
'filter_condition_callback' => array($this, '_filterBrandCondition')
));
When i hide 'options' => $valArr, , All are working fine.
I can't able to understand, why its happening. Please suggest me your ideas. Thanks in advance.
Have you already created the _filterBrandCondition function ?
What Mage_Adminhtml_Block_Catalog_Product_Renderer_Brands look like ?

Magento - Sales > Order 'Processing' status

Good morning,
We are currently using Magento and trying to list 'Processing' orders as default. We have located the status dropdown column but can't figure out how to set 'Processing' as default.
We would love some help on this,
Thank you.
$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));
A little help from Amit Bera we managed to figure this out.
Open - app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
Find - parent::__construct(); and add underneath $this->setDefaultFilter(array('status'=>'processing'));
Worked like a charm.

How to customize the database value in magento customer grid

I created new magento grid for customer module for special purpose.
In that there have a column usertype it have value as 0,1,2.
It will displayed in customer grid page as 0,1,2.
But i need to display if value is,
0 -> Inactive
1 -> Activated
2 -> Baned
How can i dothis?
This is my code grid.php in _prepareColumns() :
$this->addColumn('usertype', array(
'header' => Mage::helper('customer')->__('Usertype'),
'width' => '150',
'index' => 'usertype'
));
If this is possible in magento.
if your greed implements Mage_Adminhtml_Block_Widget_Grid I suggest you to modify
you addColumn call to
$this->addColumn('usertype',
array(
'header'=> Mage::helper('customer')->__('Usertype'),
'width' => '150px',
'index' => 'usertype',
'type' => 'options',
'options' => $values
));
Where $values should be formatted as
array( 'value_id' => 'value_label')
Now you have dropdown created with values.
Then update _prepareCollection() function and add attribute values to customer grid collection
$collection->joinAttribute('usertype', 'customer/usertype', 'entity_id', null, 'left');
I got the solution from this
By using rendere will help to load vlaues to each row.

Magento sort items ordered

When I'm in: index.php/admin/sales_order/view/order_id/[ID]/key/[KEY]/ I can see the: "Items Ordered"
I'm looking for the code where the products are loaded in this table. I want to sort the ordered items by SKU.
Any hints?
PS:
I was looking in app/code/core/Mage/Adminhtml/Block/Sales/Order/View but couldn't find anything.
$collection->getSelect()->join(array(
'item'=>$collection->getTable('sales/order_item')),
'item.order_id=`main_table`.entity_id AND item.product_type="simple"',
array(
'skus' => new Zend_Db_Expr('group_concat(item.sku SEPARATOR ", ")'),
'name' => new Zend_Db_Expr('group_concat(item.name SEPARATOR ", ")')
));
$this->addColumn('skus', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'skus',
'type' => 'text',
));
$this->addColumn('name', array(
'header' => Mage::helper('sales')->__('NAME'),
'index' => 'name',
'type' => 'text'
));
You can add SKU as an option in the Manage Attributes menu in Admin. Having done that, set it to be the default in System > Configuration > Catalog > Catalog > Product Listing Sort By.
try this
alternatively you might like this

Magento admin grid sending data from Action to Controller

I'm trying to write a custom action to run off of an admin grid that I have built. Is it possible to send a value from a column in the grid to the controller via either get or post?
I've tried googling, but I cannot find a proper explanation for this anywhere. A link to an explanation of the column settings ('getter', 'type' etc.) would also be useful if this is available.
Add this code to your Grid.php:
$this->addColumn('action',
array(
'header' => Mage::helper('yourmodulename')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('yourmodulename')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
That will build an "Edit" URL with the Id of the selected row as part of the URL. It will look something like <frontname>/<controllername>/edit/id/<value> where value is returned by the getter getId().
The getter field will execute any of the standard Magento magic getters, ie any attribute is gettable. So you could have getName or getProductUrl or getIsLeftHanded if you wanted and your controller can parse the attribute.
The controller can then retrieve that passed value using Mage::app()->getRequest()->getParam('attributename');
In terms of documentation/tutorials, have a read of this article on the website of #AlanStorm as it might help.
HTH,
JD

Resources