Skip to content

Instantly share code, notes, and snippets.

@stnc
Last active March 13, 2018 17:46
Show Gist options
  • Save stnc/1bbca3f34b11cf40b5e749753a35241a to your computer and use it in GitHub Desktop.
Save stnc/1bbca3f34b11cf40b5e749753a35241a to your computer and use it in GitHub Desktop.
Magenro admin grid new Column element (code\local\Webkul\Mpshipping\Block\Adminhtml\Mpshipping\Edit\Tab\Grid.php)
<?php
class Webkul_Mpshipping_Block_Adminhtml_Mpshipping_Edit_Tab_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('mpshippingGrid');
$this->setDefaultDir('ASC');
$this->setUseAjax(true);
$this->setSaveParametersInSession(true);
}
//https://www.atwix.com/magento/customize-orders-grid/
protected function _prepareCollection()
{
$collection = Mage::getModel('mpshipping/mpshipping')->getCollection();
$collection->getSelect()->join('marketplace_userdata', 'main_table.partner_id = marketplace_userdata.mageuserid
and marketplace_userdata.store_id=1',array('shoptitle'));
$this->setCollection($collection);
foreach ($collection as $col) {
$methodName = '';
if ($col->getShippingMethodId()) {
$methodName = Mage::getModel('mpshipping/mpshippingmethod')->load($col->getShippingMethodId())->getMethodName();
}
$collection_user = Mage::getModel('customer/customer')->load($col->partner_id);
// $collection_user ->addAttributeToSelect('firstname');
// $collection_user ->addAttributeToSelect('lastname');
$ad_soyad=$collection_user->getFirstname()." " .$collection_user->getLastname();
$col->ad_soyad=sprintf('<a href="%s" title="'.$ad_soyad.'">%s</a>',
$this->getUrl("adminhtml/customer/edit",array("id"=>$col->partner_id)),$ad_soyad);
$col->shoptitle=sprintf('<a href="%s" title="'.$col->shoptitle.'">%s</a>',
$this->getUrl("adminhtml/customer/edit",array("id"=>$col->partner_id)),$col->shoptitle);
$col->setSubmethodName($methodName);
// $col->setSubmethodName($collection_user);
}
$collection->printLogQuery(true,true);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn(
'mpshipping_id', array(
'header' => Mage::helper('mpshipping')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'mpshipping_id',
)
);
$this->addColumn(
'partner_id', array(
'header' => Mage::helper('mpshipping')->__('Seller Id'),
'align' =>'right',
'width' => '50px',
'index' => 'partner_id',
)
);
////selman
$this->addColumn(
'shoptitle', array(
'header' => Mage::helper('mpshipping')->__('Shop Title'),
'align' =>'right',
'width' => '50px',
'type' => 'text',
'index' => 'shoptitle',
// 'filter' => true,
)
);
$this->addColumn(
'ad_soyad', array(
'header' => Mage::helper('mpshipping')->__('Müşteri Ad Soyad'),
'align' =>'right',
'width' => '50px',
'type' => 'text',
'index' => 'ad_soyad',
// 'filter' => true,
)
);
//selman son
$this->addColumn(
'dest_country_id', array(
'header' => Mage::helper('mpshipping')->__('Country Id'),
'align' =>'left',
'index' => 'dest_country_id',
)
);
$this->addColumn(
'dest_region_id', array(
'header' => Mage::helper('mpshipping')->__('Region Id'),
'align' =>'left',
'index' => 'dest_region_id',
)
);
$this->addColumn(
'dest_zip', array(
'header' => Mage::helper('mpshipping')->__('ZIP From'),
'align' =>'left',
'index' => 'dest_zip',
)
);
$this->addColumn(
'dest_zip_to', array(
'header' => Mage::helper('mpshipping')->__('ZIP To'),
'align' =>'left',
'index' => 'dest_zip_to',
)
);
$this->addColumn(
'price', array(
'header' => Mage::helper('mpshipping')->__('Price'),
'align' =>'left',
'index' => 'price',
'type' => 'price',
'currency_code' => $this->getcurrency(),
)
);
$this->addColumn(
'weight_from', array(
'header' => Mage::helper('mpshipping')->__('Weight From'),
'align' =>'left',
'index' => 'weight_from',
)
);
$this->addColumn(
'weight_to', array(
'header' => Mage::helper('mpshipping')->__('Weight To'),
'align' =>'left',
'index' => 'weight_to',
)
);
$this->addColumn(
'submethod_name', array(
'header' => Mage::helper('mpshipping')->__('Sub Method Name'),
'type' => 'text',
'align' =>'left',
'index' => 'submethod_name',
'sortable' =>false,
'filter' =>false,
)
);
$this->addColumn(
'is_range', array(
'header' => Mage::helper('mpshipping')->__('Is Range'),
'align' =>'left',
'index' => 'is_range',
)
);
$this->addColumn(
'zipcode', array(
'header' => Mage::helper('mpshipping')->__('Zip Code'),
'align' =>'left',
'index' => 'zipcode',
)
);
$this->addExportType('*/*/exportCsv', Mage::helper('mpshipping')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('mpshipping')->__('XML'));
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('mpshipping_id');
$this->getMassactionBlock()->setFormFieldName('mpshipping');
$this->getMassactionBlock()->addItem(
'delete', array(
'label' => Mage::helper('mpshipping')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('mpshipping')->__('Are you sure?')
)
);
return $this;
}
private function getcurrency()
{
return (string)Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
}
public function getGridUrl()
{
return $this->getUrl("*/*/grid", array("_current"=>true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment