On the Magento administrator Dashboard I'm looking to update the 'Last 5 Orders' block so that instead of displaying the customer name, it shows the company billing name instead.
My understanding is that this can't be done using the standard reports collection, I've seen examples for doing this on the main sales grid screen, but not on the dashboard. To add further complexity this is for the latest version of Magento 1.6.1.0 and it appears the method of doing this may have changed somewhere around 1.4.
The file I believe needs editing is:
app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php
Hopefully this is one of those 'easy when you know how' solutions that lots of people can benefit from.
Here is the code
PS : I haven't got time to test this code block.
The code block available in the :
app\code\core\Mage\Adminhtml\Block\Dashboard\Tab\Customers\Most.php
protected function _prepareColumns()
{
$this->addColumn('name', array(
'header' => $this->__('Customer Name'),
'sortable' => false,
'index' => 'name'
));
$this->addColumn('orders_count', array(
'header' => $this->__('Number of Orders'),
'sortable' => false,
'index' => 'orders_count',
'type' => 'number'
));
and here is the sample link that you can override the magento admin sales grid
Override Admin Sales Order Search Grid
Related
I have 300+ shopping cart price rules. I need to solve a problem that has to do with continue following rules . I would like in the overview in the backend add the column " stop rules Further processing". Where/how should I do that?
You need to rewrite the method
Mage_Adminhtml_Block_Promo_Quote_Grid::_prepareColumns()
In your new method you need to add something like this:
$this->addColumn('stop_rules_processing', array(
'header' => Mage::helper('salesrule')->__('Stop Rule'),
'align' => 'left',
'width' => '150px',
'index' => 'stop_rules_processing',
));
Don't forget, that magento strongly do not recommend to edit core files.
I'm having this problem with adding custom columns in the order grid in Magento 1.7.0.0 and I was hoping you'd be able to give me a hand in here.
Basically I followed this guide http://www.atwix.com/magento/customize-orders-grid/ which explained I had to make a local version of /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php and make a couple of changes to have the extra columns I want. By following said guide, it said that I had to edit the function _prepareCollection() to add this line (specifying the fields I want to extract in the array)
$collection->getSelect()->join('magento_sales_flat_order_address', 'main_table.entity_id = magento_sales_flat_order_address.parent_id',array('telephone', 'email'));
Before
return parent::_prepareCollection();
And add the two columns in _prepareColumns() like this:
$this->addColumn('telephone', array(
'header' => Mage::helper('sales')->__('Telephone'),
'index' => 'telephone',
));
$this->addColumn('email', array(
'header' => Mage::helper('sales')->__('Email'),
'index' => 'email',
));
And that was it, apparently... Or maybe not, since it throws the following error when I do that:
Item (Mage_Sales_Model_Order) with the same id "XXXX" already exist
To which the solution, according to the comments underneath, was to add the following line in _prepareCollection before $this->setCollection($collection):
$collection->getSelect()->group('main_table.entity_id');
After adding the line, the Order Grid now shows the Email and Phone columns just like I want it, but turns out the pagination stopped working, it only shows the most recent 20 and it says "Pages 1 out of 1", "2 records found" on top. I can't seem to figure out why this is happening and every comment I see around doesn't go beyond the last instruction above. What could possibly be the cause of this issue?
I assume it could be replicated since I haven't made any other modifications of this model.
Alright, solved it. This is what I did:
Inspired by this answer https://stackoverflow.com/a/4219386/2009617, I made a copy of the file lib/Varien/Data/Collection/Db.php, placed it under app/core/local/Varien/Data/Collection/Db.php and copied the modifications suggested on that answer to fix the group select count error that was giving me problems above. So far it seemed to work.
However, there was a problem in the rows, when I clicked on the orders it said the Order "no longer exists", so I checked the actual url and turns out the order_id in the url was the same as the "entity_id" in the order_address table, which didn't correspond with the actual associative id of the order (parent_id). After tweaking for a long time with the MySQL query, I realized the issue was in the functions called by the _prepareColumns() and getRowUrl() functions in the /app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php I made, since they were retrieving the wrong Id. So I made the following changes:
In _prepareColumns(), within the code corresponding to the Action column, I changed the 'getter' to 'getParentId', like this:
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',
'getter' => 'getParentId',
'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,
));
}
And in the getRowUrl() function, I changed the $row statement within the getUrl() function like this:
public function getRowUrl($row)
{
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
//~ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
return $this->getUrl('*/sales_order/view', array('order_id' => $row->getParentId()));
}
return false;
}
And now it works like a charm. I hope this helps somebody else.
The problem is in query. Instead of this query:
$collection->getSelect()->join('magento_sales_flat_order_address', 'main_table.entity_id = magento_sales_flat_order_address.parent_id',array('telephone', 'email'));
You should use this:
$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id AND sales_flat_order_address.address_type = "shipping" ',array('telephone', 'email'));
In the table sales_flat_order_address, parent_id is duplicated. The first is for billing and the second one is for shipping. So you just need to select one of this: billing or shipping. This values are in column address_type...
Try using filter_index in the addColumn function:
$this->addColumn('telephone', array(
'header' => Mage::helper('sales')->__('Telephone'),
'index' => 'telephone',
'filter_index' => 'tablename.telephone'
));
You can find out the table name with printing out the sql query:
var_dump((string)$collection->getSelect())
I'm trying to add 'stock status' column to the Admin Manage Product Grid.
Stock status is either "In Stock" or "Out of Stock".
Seems like I need to edit Adminhtml/Block/Catalog/Product/Grid.php 's _prepareColumns().
I added this line
$this->addColumn('stock',
array(
'header'=> Mage::helper('catalog')->__('Stock Avail.'),
'width' => '70px',
'index' => 'status',
'type' => 'options',
'options' => Mage::getSingleton('cataloginventory/source_stock')->toOptionArray()
which just prints out Array,Array.
I'm guessing it's just printing out the type, so I would need to access the array value to get options. Am I on the right path? I can't find any good coding docs for magento, if anyone can share with me how they figured out magento, that would be really nice.
You should use a renderer: in the array of the addColumn, add:
'renderer' => 'YourNamespace_YourModule_Path_To_Renderer_File',
And the renderer file would be something like:
class YourNamespace_YourModule_Path_To_Renderer_File extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
//let's see what you have to work with
Zend_Debug::dump($row->getData(), 'debug');
$stockStatus = $row->getSomething();
return $stockStatus;
}
}
Let me know if that ain't clear
I am working on a custom module in magento admin that uses the ‘sales/order_grid_collection’ class to show the grid of all orders. The grid appears fine.
However, the first column of the grid is of ‘increment_id’, unlike the actual orders grid where the first column has checkboxes for mass action. I am getting this in spite having copy-pasted almost all the code for the _prepareColumns method from the original order module.
So I tried adding a first column of checkboxes manually inside the _prepareColumns method as follows
$this->addColumn('order_id', array(
'header_css_class' => 'a-center',
'header' => Mage::helper('sales')->__('Assigned'),
'type' => 'checkbox',
'width' => '20px',
'field_name' => 'orders[]',
'align' => 'center',
'renderer' => new Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Checkbox(),
'index' => 'order_id'
));
Upon doing this, the chekboxes do appear but they are disabled.
What am I missing here ?
Thanks
What shows up the checkboxes for mass action is the _prepareMassaction() method (see for example Mage_Adminhtml_Block_Sales_Order_Grid line 151-199 on v1.5), do you copy-pasted also in your Namespace_Module_Block_Adminhtml_Yourpath_Grid class?
If so, please paste it here to see if there is something wrong about it
I have a custom module with a backend page. In the grid, I show the customer email as the user name. By default, Magento adds a filter to every column in the grid. Now, when I try to filter by the customer's email, I get an exception saying that my custom table doesn't have an email column. Magento is trying to find that in my custom table. How can I fix this problem, or how can I remove the field of that column so that the admin can't filter by that field.
Thanks.
Add the option
'filter' => false
to the column you want to remove the filter from in the grid view (e.g. app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php)
$this->addColumn('email', array(
'header' => Mage::helper('module')->__('Email'),
'align' =>'left',
'index' => 'email',
'filter' => false,
));
I guess you meant "how can I remove the field of that column so that the admin can ' t filter by that field"
If so, I can tell you how to remove the email field.
Open /app/code/local/Namespace/Module/Block/Adminthml/Module/Grid.php
Somewhere in the protected function _prepareColumns() you should find something like :
$this->addColumn('email', array(
'header' => Mage::helper('module')->__('Email'),
'align' =>'left',
'index' => 'email',
));
Just comment this lines.
And watch out that, in the __construct method at the very beginning of the whole class, you don't have
$this->setDefaultSort('email');
If so, change it to
$this->setDefaultSort('id'); // if you have an id field in your module.
If you don't have an email column in your custom table, then I assume you're creating your grid by joining your custom table to a core table that contains the users email address, such as customer_entity.
When you filter on a column, Magento uses the column index to produce the where clause. Which in your case will give something like WHERE email LIKE '%filter value%', but it wont find email in your custom table.
You might be able to fix this by using filter_index to explicitly tell Magento which table and column to use when building the where clause. Try something like this
$this->addColumn('email', array(
'header' => Mage::helper('module')->__('Email'),
'index' => 'email',
'filter_index' => 'core_table.email',
));
where core_table is the table you are joining with.