I have Magento custom grid that is showing my list of products I want to remove my product when someone click on delete action. I have written my action code that is below but it is not working everytime when I click on delete it shows me 404 page when using url (*/*/delete) and when I changed the url to (*/*/../../admin/catalog_product/delete) it will go to dashboard page but didn't delete my product:
$this->addColumn('action',
array(
'header' => 'Action',
'width' => '100px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
)
)
)
Any solution for my this problem will really helpfull for me.
I think problem is on url making,try to make url as follow in actions.
Note : Replace param_id as per your url perameter and module name as per your module name in helper.
'actions' => array(
array(
'caption' => Mage::helper('module_name')->__('Edit'),
'url' => array(
'base'=>'*/*/edit',
'params'=> array('id'=>$this->getRequest()->getParam('param_id'))
),'field' => 'id'
),
array(
'caption' => Mage::helper('module_name')->__('Delete'),
'url' => array(
'base'=>'*/*/delete',
'params'=> array('id'=>$this->getRequest()->getParam('param_id'))
),'field' => 'id'
)
),
You haven't created a delete action, try modify the above code to:
$this->addColumn('action',
array(
'header' => 'Action',
'width' => '100px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
),
array(
'url' => array('base'=> '*/*/delete'),
'field' => 'id'
)
)
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 want to show marketplace dropdown name in magento grid but what i write in my code that display marketplace value.Bellow is my code
protected function _prepareColumns()
{
$this->addColumn('marketplace', array(
'header' => Mage::helper('adminhtml')->__('Marketplace'),
'align' =>'right',
'width' => '10px',
'index' => 'marketplace',
));
$this->addColumn('action',
array(
'header' => Mage::helper('adminhtml')->__('Action'),
'width' => '100px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(array(
'caption' => Mage::helper('adminhtml')->__('Edit'),
'url' => array('base' => '*/*/edit'),
'field' => 'id'
)),
'filter' => false,
'sortable' => false,
'index' => 'id',
));
return parent::_prepareColumns();
}
could anyone please point out what i am doing wrong as i do not have much experience in magento.
Thanking you all in advance
add field type for market place like...
$this->addColumn('marketplace', array(
'header' => Mage::helper('adminhtml')->__('Marketplace'),
'align' =>'right',
'width' => '10px',
'index' => 'marketplace'
'type' => 'options',
'options' => array(
6 => '6',
5 => '4',
4 => '4',
3 => '3',
2 => '2',
1 => '1'
),
));
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'm using yii for my web application. In one of my view I have CGridView and dataprovider is Mail model. In this model I have relation with with 3 other models. In the grid I show cols from three models. How can I filter the CGridView?
UPDATE:
<?php $dialog = $this->widget('ext.ecolumns.EColumnsDialog', array(
'options'=>array(
'title' => 'Layout settings',
'autoOpen' => false,
'show' => 'fade',
'hide' => 'fade',
),
'htmlOptions' => array('style' => 'display: none'), //disable flush of dialog content
'ecolumns' => array(
'gridId' => 'mails-grid', //id of related grid
'storage' => 'session', //where to store settings: 'db', 'session', 'cookie'
'fixedLeft' => array('CCheckBoxColumn'), //fix checkbox to the left side
'model' => $dataprovider, //model is used to get attribute labels
'columns'=>array(
array(
'name'=>'mailTemplate.name',
'filter'=>CHtml::activeTextField($dataprovider, 'mailTemplate'),
),
'sendDate',
array(
'name'=>'mailTemplate.subject',
'filter'=>CHtml::activeTextField($dataprovider, 'mailTemplate'),
),
array(
'name'=>'client.email',
'filter'=>CHtml::activeTextField($dataprovider, 'client'),
),
array(
'name'=>'client.name',
'filter'=>CHtml::activeTextField($dataprovider, 'client'),
),
array(
'name'=>'operator.username',
'filter'=>CHtml::activeTextField($dataprovider, 'operator'),
),
array(
'name'=>'status',
'value'=>array('MailHelper', 'getEmailStatus'),
'filter'=> CHtml::activeDropDownList($dataprovider, 'status', Mail::getEmailStatuses()),
),
array(
'class'=>'CButtonColumn',
'template'=>'{update}',
'buttons'=>array(
'update' => array(
'url'=>'$this->grid->controller->createUrl("/email/editTemplate", array("templateId"=>$data->id))',
),
),
)
),
)
));
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'mails-grid',
'dataProvider'=>$dataprovider->search(),
'columns' => $dialog->columns(),
'filter' => $dataprovider,
'template' => $dialog->link()."{summary}\n{items}\n{pager}",
)); ?>
I have Restaurant, City, Country and User models with relations between them.
Model:
public function search() {
$criteria=new CDbCriteria;
$criteria->together = true;
$criteria->with= array('xCountry','xCity','User');
$criteria->compare('Id',$this->Id,true);
$criteria->compare('Restaurant.Name',$this->Name,true);
$criteria->addSearchCondition('xCountry.Name',$this->Country);
$criteria->addSearchCondition('xCity.Name',$this->City);
$criteria->compare('Zip',$this->Zip,true);
$criteria->compare('Address',$this->Address,true);
$criteria->compare('Description',$this->Description,true);
$criteria->compare('Restaurant.Active',$this->Active,true);
$criteria->addSearchCondition('User.Username',$this->Owner);
$criteria->compare('Lat',$this->Lat);
$criteria->compare('Lon',$this->Lon);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
View:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'restaurant-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'Id',
'Name',
'Zip',
'Address',
'Active',
array(
'name' => 'User.Username',
'header' => 'Username',
'filter' => CHtml::activeTextField($model, 'Owner'),
'value' => '$data->User->Username',
),
array(
'name' => 'xCountry.Name',
'header' => 'Country',
'filter' => CHtml::activeTextField($model, 'Country'),
'value' => '$data->xCountry->Name',
),
array(
'name' => 'xCity.Name',
'header' => 'City',
'filter' => CHtml::activeTextField($model, 'City'),
'value' => '$data->xCity->Name',
),
array(
'class'=>'CButtonColumn',
),
),
));
I hope this can help you.
UPDATE:
What if you try something like this:
...
'columns'=>array(
'mailTemplate.name',
'sendDate',
'mailTemplate.subject',
'client.email',
...
UPDATE #2:
Prepare yourself this will be a bit dirty.
Let's say we've got two classes, A and B. B belongs to A.
B's got a property, let's say "color" and we want to display it in our grid where we list the "A"s.
The first thing you have to do is, manually create a property to your data provider class (what is "A").
This property will be "colorOfB", so you have to add "public $colorOfB;" to your model A.
Add criteria for this property:
$criteria->compare('B.color',$this->colorOfB,true);
Add the column to the grid:
array(
'name' => 'B.color',
'header' => 'Color of B',
'filter' => CHtml::activeTextField($model, 'colorOfB'),
'value' => '$data->B->color'),
The final thing is to set this property manually in A's controller:
$modelA = new A('search');
$modelA->colorOfB = $_GET['A']['colorOfB'];
this will set select list
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'avto-ugon-grid',
'dataProvider'=>$model_data,
'filter'=>$model,
'columns'=>array(
'id',
array(
'name' => 'time',
'value' => 'date("d/m/Y", $data->time)',
'type' => 'html',
),
array(
'name' => 'nomer',
'value' => '$data->nomer',
'type' => 'html',
),
array(
'name' => 'id_marka',
'value' => '$data->idMarka->mark',
'type' => 'html',
'filter'=> CHtml::listData(AvtoUgon::model()->with('idMarka')->findAll(array('group'=> 'id_marka', 'order'=> 'idMarka.mark')), 'id_marka', 'idMarka.mark'),
),
array(
'name' => 'id_model',
'value' => '$data->idModel->model',
'type' => 'html',
'filter'=> CHtml::listData(AvtoUgon::model()->with('idModel')->findAll(array('group'=> 'id_model', 'order'=> 'idModel.model')), 'id_model', 'idModel.model'),
),
array(
'name' => 'color',
'value' => $data->color,
'type' => 'raw',
),
array(
'name' => 'id_street',
'value' => '$data->idStreet->street',
'type' => 'html',
),
array(
'name' => 'publish',
'value' => 'CHtml::link($data->publish ? "Опубликовано" : "Не опубликовано", Yii::app()->controller->createUrl("publish", array("id" => $data->id)))',
'type' => 'html',
),
/*'id_street',
'nomer',
*/
array(
'class'=>'CButtonColumn',
),
),
));