Related
I have created a custom orders grid in the admin panel which shows me the payment method and the shipping method of the order.
Here is my custom Grid.php:
<?PHP
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()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$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')->__('Клиент'),
'index' => 'billing_name',
));
$this->addColumn('grand_totals', array(
'header' => Mage::helper('sales')->__('Авансово плащане'),
'index' => 'increment_id',
'width' => '100px',
'renderer' => 'Mage_Adminhtml_Block_Sales_Order_AvansRenderer',
));
$this->addColumn('avans', array(
'header' => Mage::helper('sales')->__('Плащане при доставка'),
'index' => 'increment_id',
'width' => '50px',
'renderer' => 'Mage_Adminhtml_Block_Sales_Order_BeforeDelRenderer',
));
$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('Тотал'),
'index' => 'increment_id',
'width' => '100px',
'renderer' => 'Mage_Adminhtml_Block_Sales_Order_TotalRenderer',
));
$this->addColumn('shipping_description', array(
'header' => Mage::helper('sales')->__('Начин на доставка'),
'index' => 'shipping_description',
));
$this->addColumn('payment_method',
array(
'header'=> Mage::helper('catalog')->__('Начин на плащане'),
'width' => '230px',
'index' => 'method',
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_PaymentMethodRenderer',
));
$this->addColumn('shipping_description', array(
'header' => Mage::helper('sales')->__('Начин на доставка'),
'index' => 'shipping_description',
));
$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',
'data-column' => 'action',
)
),
'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();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('order_ids');
$this->getMassactionBlock()->setUseSelectAll(false);
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
$this->getMassactionBlock()->addItem('cancel_order', array(
'label'=> Mage::helper('sales')->__('Cancel'),
'url' => $this->getUrl('*/sales_order/massCancel'),
));
}
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
$this->getMassactionBlock()->addItem('hold_order', array(
'label'=> Mage::helper('sales')->__('Hold'),
'url' => $this->getUrl('*/sales_order/massHold'),
));
}
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
$this->getMassactionBlock()->addItem('unhold_order', array(
'label'=> Mage::helper('sales')->__('Unhold'),
'url' => $this->getUrl('*/sales_order/massUnhold'),
));
}
$this->getMassactionBlock()->addItem('pdfinvoices_order', array(
'label'=> Mage::helper('sales')->__('Print Invoices'),
'url' => $this->getUrl('*/sales_order/pdfinvoices'),
));
$this->getMassactionBlock()->addItem('pdfshipments_order', array(
'label'=> Mage::helper('sales')->__('Print Packingslips'),
'url' => $this->getUrl('*/sales_order/pdfshipments'),
));
$this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
'label'=> Mage::helper('sales')->__('Print Credit Memos'),
'url' => $this->getUrl('*/sales_order/pdfcreditmemos'),
));
$this->getMassactionBlock()->addItem('pdfdocs_order', array(
'label'=> Mage::helper('sales')->__('Print All'),
'url' => $this->getUrl('*/sales_order/pdfdocs'),
));
$this->getMassactionBlock()->addItem('print_shipping_label', array(
'label'=> Mage::helper('sales')->__('Print Shipping Labels'),
'url' => $this->getUrl('*/sales_order_shipment/massPrintShippingLabel'),
));
return $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 false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
This code is giving me the following result:
As you can see the filter inputs for the two shipping_description and payment_method are simple text inputs.
How can i make them dropdown menus containing the proper information with the all shipping method descriptions and all payment_method title?
How can i make them filterable after that?
I hope i have explained my question well. Looking forward for your help and answers.
I have a custom module and this lists some records in the admin panel. Currently there is no link to the list of records and I want to give a custom link to the listing. I have tried to overwrite the grid block class. But this is not working.
Code is given below:
<config>
<global>
<blocks>
...
<adminhtml>
<rewrite>
<partners_grid>Tech_SecodaryProduct_Block_Adminhtml_Partners_Grid</partners_grid>
</rewrite>
</adminhtml>
...
</blocks>
</global>
I have created a file under local/Tech/SecodaryProduct/Block/Adminhtml/Partners/Grid.php
<?php
class Tech_SecodaryProduct_Block_Adminhtml_Partners_Grid extends Webkul_Marketplace_Block_Adminhtml_Partners_Grid
{
protected function _prepareColumns(){
// parent::__construct();
$this->addColumn('partnerstatus', array(
'header' => Mage::helper('customer')->__('Seller Status'),
'index' => 'partnerstatus',
));
$ispartnerEnabled = Mage::helper('core/data')->isModuleOutputEnabled('Webkul_Mppartnergroup');
if($ispartnerEnabled == 1){
$this->addColumn('group', array(
'header' => Mage::helper('customer')->__('Group'),
'index' => 'group',
));
}
$this->addColumn('order', array(
'header' => Mage::helper('customer')->__('Order'),
'index' => 'order',
'type' => 'text',
"filter" => false,
"sortable" => false
));
$isThisEnabled = Mage::helper('core/data')->isModuleOutputEnabled('Webkul_Sellerstatus');
if($isThisEnabled == 1){
$this->addColumn('sellerstatus', array(
'header' => Mage::helper('customer')->__('Seller Status'),
'type' => 'text',
'index' => 'sellerstatus',
"filter" => false,
"sortable" => false
));
}
$this->addColumn('Telephone', array(
'header' => Mage::helper('customer')->__('Telephone'),
'width' => '100',
'index' => 'billing_telephone',
));
$this->addColumn('billing_postcode', array(
'header' => Mage::helper('customer')->__('ZIP'),
'width' => '90',
'index' => 'billing_postcode',
));
$this->addColumn('billing_country_id', array(
'header' => Mage::helper('customer')->__('Country'),
'width' => '100',
'type' => 'country',
'index' => 'billing_country_id',
));
$this->addColumn('billing_region', array(
'header' => Mage::helper('customer')->__('State/Province'),
'width' => '100',
'index' => 'billing_region',
));
$this->addColumn('customer_since', array(
'header' => Mage::helper('customer')->__('Seller Since'),
'type' => 'datetime',
'align' => 'center',
'index' => 'created_at',
'gmtoffset' => true,
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('website_id', array(
'header' => Mage::helper('customer')->__('Website'),
'align' => 'center',
'width' => '80px',
'type' => 'options',
'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
'index' => 'website_id',
));
}
$this->addColumn('deny', array(
'header' => Mage::helper('marketplace')->__('Reason'),
'index' => 'deny',
'type' => 'text',
'filter' => false,
'sortable' => false
));
$this->addExportType('*/*/exportCsv', Mage::helper('marketplace')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('marketplace')->__('XML'));
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
}
}
I want to rewrite the following class
<?php
class Webkul_Marketplace_Block_Adminhtml_Partners_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
But my changes aren't reflecting in the admin panel. I have searched a lot about this problem but no solution is working.
Thanks in advance.
I am trying to add column in my sales_order grid. My column will be seller name of the product. I have a multivendor marketplace extension.
I find the seller id which is the customer id but I can find the full name with the help of seller id.
I trying to solve it and here is the code that i used.
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('marketplace_saleslist', 'main_table.entity_id = marketplace_saleslist.mageorderid',array('mageproownerid'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
And now I add the following column.
$this->addColumn('mageproownerid', array(
'header' => Mage::helper('sales')->__('Seller ID'),
'index' => 'mageproownerid',
));
The Grid.php is :
public function __construct()
{
parent::__construct();
$this->setId('sales_order_grid');
$this->setUseAjax(true);
$this->setDefaultSort('created_at');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('marketplace_saleslist', 'main_table.entity_id = marketplace_saleslist.mageorderid',array('mageproownerid'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$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' => 'date',
'format'=> 'M/d/y',
'width' => '100px',
));
$this->addColumn('mageproownerid', array(
'header' => Mage::helper('sales')->__('Seller ID'),
'index' => 'mageproownerid',
));
$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'=>'adminhtml/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();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('order_ids');
$this->getMassactionBlock()->setUseSelectAll(false);
$this->getMassactionBlock()->addItem('approve_order', array(
'label'=> Mage::helper('sales')->__('Approve Order'),
'url' => $this->getUrl('*/*/massstatus'),
));
return $this;
}
public function getRowUrl($row)
{
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId()));
}
return false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
I want to relate the above table with "customer_account" table using join on "marketplace_saleslist" field "mageproownerid".
How can we find the customer fullname.
Please let me know the solutions.
Thanks and regards.
You can create helper function and change column in grid.php file
$this->addColumn('mageproownerid', array(
'header' => Mage::helper('sales')->__('Seller ID'),
'index' => 'mageproownerid',
'type' => 'options',
'options' => Mage::helper('yourmodule')->getCustomerName(),
));
I will try my best to explain what I am doing.
I have manually added four columns in grid.php file for sales/order grid.
Now it's showing the wrong count in the total records.
There are more than 1500 records, but it shows only 1190.
So here is the code grid.php file.
<?php
class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function callback_skus($value, $row, $column, $isExport)
{
$increment_id = $value;
$_order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);
$_items = $_order->getAllItems();
$skus="";
foreach ($_items as $item)
{
$skus .= $item->getSku()."<br />";
}
return $skus;
}
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()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order_payment', 'sales_flat_order_payment.parent_id = main_table.entity_id',array('method'));
$collection->getSelect()->group('main_table.entity_id');
$collection->getSelect()->group('sales_flat_order_payment.parent_id');
$collection->getSelect()->join('sales_flat_shipment_track', 'main_table.entity_id = sales_flat_shipment_track.order_id',array('track_number'=> new Zend_Db_Expr('group_concat(DISTINCT `sales_flat_shipment_track`.track_number SEPARATOR ", ")'),'title' => new Zend_Db_Expr('(SELECT group_concat(`sales_flat_shipment_track`.title SEPARATOR ", ")FROM `sales_flat_shipment_track` As `sales_flat_shipment_track` WHERE `main_table`.`entity_id` = `sales_flat_shipment_track`.`order_id` )')));
$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('country_id'));
$collection->getSelect()->joinLeft('sales_flat_order_item', 'main_table.entity_id = sales_flat_order_item.order_id',array('sku'));
$collection->getSelect()->group('main_table.entity_id');
$this->setCollection($collection);
$orders = Mage::getResourceModel('sales/order_collection');
foreach($orders as $order){
$items = $order->getAllVisibleItems();
foreach($items as $item){
$sku = $item->getSku();
}
}
$collection->getSize();
$collection->count();
return parent::_prepareCollection();
}
public function count()
{
$this->load();
return count($this->_prepareColumns);
}
protected function _prepareColumns()
{
$this->addColumn('sku', array(
'header' => Mage::helper('sales')->__('SKU#'),
'index' => 'increment_id',
'width' => '80px',
'frame_callback' => array($this, 'callback_skus'),
'filter_index' => 'sales_flat_order_item.sku',
));
$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
));
$this->addColumn('country_id', array(
'header'=> Mage::helper('sales')->__('Shipping Country'),
'width' => '80px',
'type' => 'text',
'index' => 'country_id',
));
$this->addColumn('method', array(
'header'=> Mage::helper('sales')->__('Payment Method'),
'width' => '80px',
'type' => 'text',
'index' => 'method',
));
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(),
));
$this->addColumn('track_number', array(
'header'=> Mage::helper('sales')->__(' Track Number'),
'width' => '80px',
'type' => 'text',
'index' => 'track_number',
));
$this->addColumn('title', array(
'header'=> Mage::helper('sales')->__('Title'),
'width' => '80px',
'index' => 'title',
));
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',
'data-column' => 'action',
)
),
'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();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('order_ids');
$this->getMassactionBlock()->setUseSelectAll(false);
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
$this->getMassactionBlock()->addItem('cancel_order', array(
'label'=> Mage::helper('sales')->__('Cancel'),
'url' => $this->getUrl('*/sales_order/massCancel'),
));
}
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
$this->getMassactionBlock()->addItem('hold_order', array(
'label'=> Mage::helper('sales')->__('Hold'),
'url' => $this->getUrl('*/sales_order/massHold'),
));
}
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
$this->getMassactionBlock()->addItem('unhold_order', array(
'label'=> Mage::helper('sales')->__('Unhold'),
'url' => $this->getUrl('*/sales_order/massUnhold'),
));
}
$this->getMassactionBlock()->addItem('pdfinvoices_order', array(
'label'=> Mage::helper('sales')->__('Print Invoices'),
'url' => $this->getUrl('*/sales_order/pdfinvoices'),
));
$this->getMassactionBlock()->addItem('pdfshipments_order', array(
'label'=> Mage::helper('sales')->__('Print Packingslips'),
'url' => $this->getUrl('*/sales_order/pdfshipments'),
));
$this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
'label'=> Mage::helper('sales')->__('Print Credit Memos'),
'url' => $this->getUrl('*/sales_order/pdfcreditmemos'),
));
$this->getMassactionBlock()->addItem('pdfdocs_order', array(
'label'=> Mage::helper('sales')->__('Print All'),
'url' => $this->getUrl('*/sales_order/pdfdocs'),
));
$this->getMassactionBlock()->addItem('print_shipping_label', array(
'label'=> Mage::helper('sales')->__('Print Shipping Labels'),
'url' => $this->getUrl('*/sales_order_shipment/massPrintShippingLabel'),
));
return $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 false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
Now I have written my code for joining table and access it from the grid in _prepareCollections() function.
Added 4 columns in _addcolumns() function. I am adding payment method, Sku, title, track_number.
Problem
total records 1190 found.
But it should show all 1500 records.
Please let me know what I have to do.
Also please refer the link for my previous problem my previous problem link
I have got the solution(Ryan helped me out). There will not be always all the shipment tracking number and also the payment.
So here we need to use joinLeft on sales_flat_shipment_track and sales_flat_order_payment.
Hence it works. ! :)
I've been writing a custom out of stock module for the magento backend, I have mass actions, export etc working. However when i do any sort of search function (like put something in the product name field) and indeed try to change to the next page (or input a specific page into the field) or how many products appear on a page. It immediately redirects me to the dashboard.
Can anyone point me in the right direction as to where the code is that handles this function? I'm going to assume its part of the controller, but i've been searching for the last hour and is now time to ask for help!!
Thanks for any help you can provide!
Prepare columns function:
protected function _prepareColumns()
{
$this->addColumn('sku',
array(
'header'=> Mage::helper('catalog')->__('SKU'),
'width' => '80px',
'index' => 'sku',
));
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
$this->addColumn('set_name',
array(
'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
'width' => '60px',
'index' => 'attribute_set_id',
'type' => 'options',
'options' => $sets,
));
$store = $this->_getStore();
if ($store->getId()) {
$this->addColumn('custom_name',
array(
'header'=> Mage::helper('catalog')->__('Name in %s', $store->getName()),
'index' => 'custom_name',
));
}
$this->addColumn('name',
array(
'header'=> Mage::helper('catalog')->__('Name'),
'index' => 'name',
));
$this->addColumn('stock_status',
array(
'header'=> 'Availability',
'width' => '60px',
'index' => 'stock_status',
'type' => 'options',
'options' => array('1'=>'In stock','0'=>'Out of stock'),
));
$this->addColumn('custom_stock_status',
array(
'header' => 'Custom Stock Status',
'width' => '60px',
'index' => 'custom_stock_status',
'type' => 'options',
'editable' => 'true',));
$this->addColumn('eol',
array(
'header'=> Mage::helper('catalog')->__('EoL'),
'width' => '20px',
'type' => 'checkbox',
'index' => 'eol',
'onclick' => 'this.value = this.checked ? 1 : 0;',
'values' => array('1','2'),
'editable' => 'true',
));
$store = $this->_getStore();
$this->addColumn('qty',
array(
'header'=> Mage::helper('catalog')->__('Qty'),
'width' => '25px',
'type' => 'number',
'index' => 'qty',
));
$this->addColumn('status',
array(
'header'=> Mage::helper('catalog')->__('Status'),
'width' => '70px',
'index' => 'status',
'type' => 'options',
'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
));
$this->addColumn('action',
array(
'header' => Mage::helper('catalog')->__('Action'),
'width' => '90px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Edit Product'),
'url' => array(
'base'=>'store_admin/catalog_product/edit',
'params'=>array('store'=>$this->getRequest()->getParam('store'))
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
));
$this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS'));
return parent::_prepareColumns();
}
Furthermore i'm trying to filter by an attribute, I need to filter the same attribute twice in order to output both null and no attributes, but not yes. Is there anyway to do this?
->addAttributeToFilter('eol', array('null' => true), 'left')
->addAttributeToFilter('eol', array('No' => true));
This is what i'm trying to do at the moment, however, it doesn't work in the slightest. Both work individually fine!
Mage_Adminhtml_Block_Widget_Grid
has a method
_addColumnFilterToCollection($column)
You can override it to implement filtering logic for your custom grid.
For CE 1.6.2, this worked for me:
1) Copy over app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php to app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php
2) add the code below from app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php inside/under _prepareCollection()
AFTER ->addAttributeToSelect('type_id'); and before if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
CODE:
$collection->joinTable( 'cataloginventory/stock_item',
'product_id=entity_id', array("stock_status" => "is_in_stock") )
->addAttributeToSelect('stock_status');
3) Add the below around line 180 after
'index' => 'price', ));
CODE:
$this->addColumn('stock_status',
array(
'header'=> 'Stock Status', // this is the title of the column
'width' => '60px', // this is the width of the column
'index' => 'stock_status',
'type' => 'options',
'options' => array('1'=>'In Stock','0'=>'Out Of Stock'),
)
);