Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Grid.php
Go to the documentation of this file.
1 <?php
7 
14 class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
15 {
21  protected $_websiteId;
22 
28  protected $_conditionName;
29 
33  protected $_tablerate;
34 
39 
47  public function __construct(
48  \Magento\Backend\Block\Template\Context $context,
49  \Magento\Backend\Helper\Data $backendHelper,
50  \Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\CollectionFactory $collectionFactory,
51  \Magento\OfflineShipping\Model\Carrier\Tablerate $tablerate,
52  array $data = []
53  ) {
54  $this->_collectionFactory = $collectionFactory;
55  $this->_tablerate = $tablerate;
56  parent::__construct($context, $backendHelper, $data);
57  }
58 
64  protected function _construct()
65  {
66  parent::_construct();
67  $this->setId('shippingTablerateGrid');
68  $this->_exportPageSize = 10000;
69  }
70 
77  public function setWebsiteId($websiteId)
78  {
79  $this->_websiteId = $this->_storeManager->getWebsite($websiteId)->getId();
80  return $this;
81  }
82 
88  public function getWebsiteId()
89  {
90  if ($this->_websiteId === null) {
91  $this->_websiteId = $this->_storeManager->getWebsite()->getId();
92  }
93  return $this->_websiteId;
94  }
95 
102  public function setConditionName($name)
103  {
104  $this->_conditionName = $name;
105  return $this;
106  }
107 
113  public function getConditionName()
114  {
115  return $this->_conditionName;
116  }
117 
123  protected function _prepareCollection()
124  {
126  $collection = $this->_collectionFactory->create();
127  $collection->setConditionFilter($this->getConditionName())->setWebsiteFilter($this->getWebsiteId());
128 
129  $this->setCollection($collection);
130 
131  return parent::_prepareCollection();
132  }
133 
139  protected function _prepareColumns()
140  {
141  $this->addColumn(
142  'dest_country',
143  ['header' => __('Country'), 'index' => 'dest_country', 'default' => '*']
144  );
145 
146  $this->addColumn(
147  'dest_region',
148  ['header' => __('Region/State'), 'index' => 'dest_region', 'default' => '*']
149  );
150 
151  $this->addColumn(
152  'dest_zip',
153  ['header' => __('Zip/Postal Code'), 'index' => 'dest_zip', 'default' => '*']
154  );
155 
156  $label = $this->_tablerate->getCode('condition_name_short', $this->getConditionName());
157  $this->addColumn('condition_value', ['header' => $label, 'index' => 'condition_value']);
158 
159  $this->addColumn('price', ['header' => __('Shipping Price'), 'index' => 'price']);
160 
161  return parent::_prepareColumns();
162  }
163 }
__()
Definition: __.php:13
$label
Definition: details.phtml:21
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\CollectionFactory $collectionFactory, \Magento\OfflineShipping\Model\Carrier\Tablerate $tablerate, array $data=[])
Definition: Grid.php:47
if(!isset($_GET['name'])) $name
Definition: log.php:14