_getHelper(); parent::__construct(); $this->setId('pacsoftGrid'); $this->setDefaultSort('pk'); $this->setDefaultDir('ASC'); $this->setSaveParametersInSession(true); $this->setUseAjax(true); $this->_exportPageSize = 10000; $this->setEmptyText($helper->__('No shipping rates found.')); } public function getWebsiteId() { return $this->_getHelper()->getWebsiteId($this->getWebsite()); } protected function _getHelper() { return Mage::helper('pacsoft/rates'); } protected function _prepareCollection() { $websiteId = $this->getWebsiteId(); $collection = Mage::getModel('pacsoft/rate')->getCollection(); $select = $collection->getSelect(); $select->where('active = 1'); if ($websiteId) $select->where('website_id = ?', $websiteId); else $select->where('website_id = -1'); $this->setCollection($collection); return parent::_prepareCollection(); } protected function getDestCountryOptions() { $helper = $this->_getHelper(); $options = array(); $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(false); if (isset($countries[0]) && !$countries[0]['value']) { //$countries[0] = array('value' => '*', 'label' => '*', ); unset($countries[0]); } foreach ($countries as $country) { $options[$country['value']] = $country['label']; } return $options; } protected function getConditionNameOptions() { $options = array(); $names = Mage::getModel('adminhtml/system_config_source_shipping_tablerate')->toOptionArray(); foreach ($names as $name) { $options[$name['value']] = $name['label']; } return $options; } protected function _getStore() { $storeId = (int) $this->getRequest()->getParam('store', 0); return Mage::app()->getStore($storeId); } protected function _filterCountryCondition($collection, $column) { if (!$value = $column->getFilter()->getValue()) { return; } $this->getCollection()->addFieldToFilter('dest_country_id', array('like' => "%$value%")); } protected function _prepareColumns() { parent::_prepareColumns(); $helper = $this->_getHelper(); $this->addColumn('dest_country_id', array( 'header' => $helper->__('Country'), 'align' => 'left', 'index' => 'dest_country_id', 'filter_condition_callback' => array($this, '_filterCountryCondition'), 'renderer' => 'pacsoft/adminhtml_rates_grid_column_renderer_country', 'type' => 'options', 'options' => $this->getDestCountryOptions(), )); $this->addColumn('dest_region', array( 'header' => $helper->__('Region/State'), 'align' =>'left', 'index' => 'dest_region', 'filter_index' => 'region_table.code', 'filter' => 'pacsoft/adminhtml_rates_grid_column_filter_region', 'default' => '*', )); $this->addColumn('dest_city', array( 'header' => $helper->__('City'), 'align' =>'left', 'index' => 'dest_city', 'filter' => 'pacsoft/adminhtml_rates_grid_column_filter_city', 'renderer' => 'pacsoft/adminhtml_rates_grid_column_renderer_city', 'default' => '*', )); $this->addColumn('dest_zip', array( 'header' => $helper->__('Zip/Postal Code From'), 'align' =>'left', 'index' => 'dest_zip', 'filter' => 'pacsoft/adminhtml_rates_grid_column_filter_zip', 'renderer' => 'pacsoft/adminhtml_rates_grid_column_renderer_zip', 'default' => '*', )); $this->addColumn('dest_zip_to', array( 'header' => $helper->__('Zip/Postal Code To'), 'align' =>'left', 'index' => 'dest_zip_to', 'filter' => 'pacsoft/adminhtml_rates_grid_column_filter_zip', 'renderer' => 'pacsoft/adminhtml_rates_grid_column_renderer_zip', 'default' => '*', )); $this->addColumn('condition_name', array( 'header' => $helper->__('Condition Name'), 'align' => 'left', 'index' => 'condition_name', 'type' => 'options', 'options' => $this->getConditionNameOptions(), )); $this->addColumn('condition_from_value', array( 'header' => $helper->__('Condition Value From'), 'align' => 'left', 'index' => 'condition_from_value', 'type' => 'number', 'default' => '0', )); $this->addColumn('condition_to_value', array( 'header' => $helper->__('Condition Value To'), 'align' => 'left', 'index' => 'condition_to_value', 'type' => 'number', 'default' => '0', )); //$store = $this->_getStore(); $this->addColumn('price', array( 'header' => $helper->__('Price'), 'align' => 'left', 'index' => 'price', 'type' => 'price', 'currency_code' => Mage::app()->getWebsite($this->getWebsiteId())->getBaseCurrency()->getCode(), 'default' => '0.00', )); $this->addColumn('cost', array( 'header' => $helper->__('Cost'), 'align' => 'left', 'index' => 'cost', 'type' => 'price', 'currency_code' => Mage::app()->getWebsite($this->getWebsiteId())->getBaseCurrency()->getCode(), 'default' => '0.00', )); $this->addColumn('service', array( 'header' => $helper->__('Service'), 'align' => 'left', 'index' => 'service', 'type' => 'text', 'default' => '', )); $this->addColumn('addons', array( 'header' => $helper->__('Add-ons'), 'align' => 'left', 'index' => 'addons', 'type' => 'text', 'default' => '', )); $this->addColumn('title', array( 'header' => $helper->__('Title'), 'align' => 'left', 'index' => 'title', 'type' => 'text', 'default' => '', )); $this->addColumn('sort_order', array( 'header' => $helper->__('Sort Order'), 'align' => 'left', 'index' => 'sort_order', 'type' => 'number', 'default' => '0', )); $this->addColumn('external_id', array( 'header' => $helper->__('External ID'), 'align' => 'left', 'index' => 'external_id', 'type' => 'text', 'default' => '', )); //$this->addExportType('*/*/exportCsv', $helper->__('CSV')); return $this; } public function getRowUrl($row) { return $this->getUrl('*/*/edit', array('website' => $this->getWebsiteId(), 'pk' => $row->getId())); } public function getGridUrl() { return $this->getUrl('*/*/grid', array('_current' => true)); } protected function _prepareMassaction() { $helper = $this->_getHelper(); $this->setMassactionIdField('pk'); $this->getMassactionBlock()->setFormFieldName('pk'); $this->getMassactionBlock()->addItem('delete', array( 'label' => $helper->__('Delete'), 'url' => $this->getUrl('*/*/massDelete', array('website' => $this->getWebsiteId())), 'confirm' => $helper->__('Are you sure?') )); return $this; } }