1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Shipping carrier table rate grid block
29: * WARNING: This grid used for export table rates
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid extends Mage_Adminhtml_Block_Widget_Grid
36: {
37: /**
38: * Website filter
39: *
40: * @var int
41: */
42: protected $_websiteId;
43:
44: /**
45: * Condition filter
46: *
47: * @var string
48: */
49: protected $_conditionName;
50:
51: /**
52: * Define grid properties
53: *
54: * @return void
55: */
56: public function __construct()
57: {
58: parent::__construct();
59: $this->setId('shippingTablerateGrid');
60: $this->_exportPageSize = 10000;
61: }
62:
63: /**
64: * Set current website
65: *
66: * @param int $websiteId
67: * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
68: */
69: public function setWebsiteId($websiteId)
70: {
71: $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId();
72: return $this;
73: }
74:
75: /**
76: * Retrieve current website id
77: *
78: * @return int
79: */
80: public function getWebsiteId()
81: {
82: if (is_null($this->_websiteId)) {
83: $this->_websiteId = Mage::app()->getWebsite()->getId();
84: }
85: return $this->_websiteId;
86: }
87:
88: /**
89: * Set current website
90: *
91: * @param int $websiteId
92: * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
93: */
94: public function setConditionName($name)
95: {
96: $this->_conditionName = $name;
97: return $this;
98: }
99:
100: /**
101: * Retrieve current website id
102: *
103: * @return int
104: */
105: public function getConditionName()
106: {
107: return $this->_conditionName;
108: }
109:
110: /**
111: * Prepare shipping table rate collection
112: *
113: * @return Mage_Adminhtml_Block_Shipping_Carrier_Tablerate_Grid
114: */
115: protected function _prepareCollection()
116: {
117: /** @var $collection Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection */
118: $collection = Mage::getResourceModel('shipping/carrier_tablerate_collection');
119: $collection->setConditionFilter($this->getConditionName())
120: ->setWebsiteFilter($this->getWebsiteId());
121:
122: $this->setCollection($collection);
123:
124: return parent::_prepareCollection();
125: }
126:
127: /**
128: * Prepare table columns
129: *
130: * @return Mage_Adminhtml_Block_Widget_Grid
131: */
132: protected function _prepareColumns()
133: {
134: $this->addColumn('dest_country', array(
135: 'header' => Mage::helper('adminhtml')->__('Country'),
136: 'index' => 'dest_country',
137: 'default' => '*',
138: ));
139:
140: $this->addColumn('dest_region', array(
141: 'header' => Mage::helper('adminhtml')->__('Region/State'),
142: 'index' => 'dest_region',
143: 'default' => '*',
144: ));
145:
146: $this->addColumn('dest_zip', array(
147: 'header' => Mage::helper('adminhtml')->__('Zip/Postal Code'),
148: 'index' => 'dest_zip',
149: 'default' => '*',
150: ));
151:
152: $label = Mage::getSingleton('shipping/carrier_tablerate')
153: ->getCode('condition_name_short', $this->getConditionName());
154: $this->addColumn('condition_value', array(
155: 'header' => $label,
156: 'index' => 'condition_value',
157: ));
158:
159: $this->addColumn('price', array(
160: 'header' => Mage::helper('adminhtml')->__('Shipping Price'),
161: 'index' => 'price',
162: ));
163:
164: return parent::_prepareColumns();
165: }
166: }
167: