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.
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 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 have made a custom customer grid for magento admin panel.
It shows perfectly but the problem is that when I click search button it returns page without any theme.
please look into snapshots and code.
after clicking search button, it shows this,
I have written following code to generate this.
[company]/[namespace]/Design/Block/Customer/Grid.php
<?php
class Company_Namespace_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
//$this->addAttributeToSort('entity_id', 'desc');
// $this->setId('customerGrid');
// $this->setUseAjax(true);
// $this->setDefaultSort('entity_id');
// $this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
->joinAttribute('billing_company', 'customer_address/company', 'default_billing', null, 'left')
->addAttributeToSort('entity_id', 'desc');
;
$collection->addAttributeToSelect('company');
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('entity_id', array(
'header' => Mage::helper('customer')->__('ID'),
'width' => '50px',
'index' => 'entity_id',
'type' => 'number',
));
$this->addColumn('company', array(
'header' => Mage::helper('customer')->__('Company'),
'width' => '150',
'index' => 'billing_company'
));
$this->addColumn('email', array(
'header' => Mage::helper('customer')->__('Email'),
'width' => '150',
'index' => 'email'
));
$groups = Mage::getResourceModel('customer/group_collection')
->addFieldToFilter('customer_group_id', array('gt'=> 0))
->load()
->toOptionHash();
$this->addColumn('group', array(
'header' => Mage::helper('customer')->__('Group'),
'width' => '100',
'index' => 'group_id',
'type' => 'options',
'options' => $groups,
));
$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')->__('Customer 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('action',
array(
'header' => Mage::helper('customer')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('customer')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
parent::_prepareMassaction();
// $this->setMassactionIdField('entity_id');
// $this->getMassactionBlock()->setFormFieldName('customer');
// $this->getMassactionBlock()->addItem('delete', array(
// 'label' => Mage::helper('customer')->__('Delete'),
// 'url' => $this->getUrl('*/*/massDelete'),
// 'confirm' => Mage::helper('customer')->__('Are you sure?')
// ));
// $this->getMassactionBlock()->addItem('newsletter_subscribe', array(
// 'label' => Mage::helper('customer')->__('Subscribe to Newsletter'),
// 'url' => $this->getUrl('*/*/massSubscribe')
// ));
// $this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
// 'label' => Mage::helper('customer')->__('Unsubscribe from Newsletter'),
// 'url' => $this->getUrl('*/*/massUnsubscribe')
// ));
// $groups = $this->helper('customer')->getGroups()->toOptionArray();
// array_unshift($groups, array('label'=> '', 'value'=> ''));
// $this->getMassactionBlock()->addItem('assign_group', array(
// 'label' => Mage::helper('customer')->__('Assign a Customer Group'),
// 'url' => $this->getUrl('*/*/massAssignGroup'),
// 'additional' => array(
// 'visibility' => array(
// 'name' => 'group',
// 'type' => 'select',
// 'class' => 'required-entry',
// 'label' => Mage::helper('customer')->__('Group'),
// 'values' => $groups
// )
// )
// ));
// return $this;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=> true));
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
}
}
and
my config.xml
<adminhtml>
<rewrite>
<customer_grid>Company_Namespace_Block_Customer_Grid</customer_grid>
<!-- rewrite the customer grid -->
</rewrite>
</adminhtml>
</blocks>
I see that you commented out $this->setUseAjax(true); in the __construct method. Put it back.
You can do the same for $this->setSaveParametersInSession(true); but it's not mandatory.
I have solved it
Edited code for __costruct method
public function __construct()
{
parent::__construct();
// $this->addAttributeToSort('entity_id', 'desc');
$this->setId('customerGrid');
$this->setUseAjax(true);
$this->setDefaultSort('entity_id');
$this->setSaveParametersInSession(true);
}
I want to create select type for a grid column in magento admin panel.inside _prepareColumns() function
protected function _prepareColumns()
{
if (!$this->getCategory()->getProductsReadonly()) {
$this->addColumn('in_category', array(
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_category',
'values' => $this->_getSelectedProducts(),
'align' => 'center',
'index' => 'entity_id'
));
}
$this->addColumn('entity_id', array(
'header' => Mage::helper('catalog')->__('ID'),
'sortable' => true,
'width' => '60',
'index' => 'entity_id'
));
$this->addColumn('name', array(
'header' => Mage::helper('catalog')->__('Name'),
'index' => 'name'
));
$this->addColumn('position', array(
'header' => Mage::helper('catalog')->__('Position'),
'width' => '1',
'type' => 'select',
'index' => 'position',
'editable' => !$this->getCategory()->getProductsReadonly()
//'renderer' => 'adminhtml/widget_grid_column_renderer_input'
));
return parent::_prepareColumns();
}
Magento uses addColumn() function to create grid column, I want to create a column with select type, but I don't know how to provide it with options
Grid.php
$this->addColumn('state', array(
'header' => Mage::helper('modulename')->__('State'),
'index' => 'state',
'type' => 'options',
'options'=> Mage::getModel('modulename/customerstate')->getStates()
));
Model/Customerstate.php
public function getStates() {
$statesArray = array();
foreach($this->getCollection() as $state){
$statesArray[$state->getId()] = $state->getState();
}
return $statesArray;
}
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'),
)
);