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\Reports\Block\Adminhtml\Grid\Shopcart
15 {
20 
24  protected $queryResolver;
25 
33  public function __construct(
34  \Magento\Backend\Block\Template\Context $context,
35  \Magento\Backend\Helper\Data $backendHelper,
36  \Magento\Quote\Model\QueryResolver $queryResolver,
37  \Magento\Reports\Model\ResourceModel\Quote\Item\CollectionFactory $quoteItemCollectionFactory,
38  array $data = []
39  ) {
40  $this->quoteItemCollectionFactory = $quoteItemCollectionFactory;
41  $this->queryResolver = $queryResolver;
42  parent::__construct($context, $backendHelper, $data);
43  }
44 
48  protected function _construct()
49  {
50  parent::_construct();
51  $this->setId('gridProducts');
52  }
53 
57  protected function _prepareCollection()
58  {
60  $collection = $this->quoteItemCollectionFactory->create();
61  $collection->prepareActiveCartItems();
62  $this->setCollection($collection);
63  return parent::_prepareCollection();
64  }
65 
69  protected function _prepareColumns()
70  {
71  $this->addColumn(
72  'product_id',
73  [
74  'header' => __('ID'),
75  'align' => 'right',
76  'index' => 'product_id',
77  'sortable' => false,
78  'header_css_class' => 'col-id',
79  'column_css_class' => 'col-id'
80  ]
81  );
82 
83  $this->addColumn(
84  'name',
85  [
86  'header' => __('Product'),
87  'index' => 'name',
88  'sortable' => false,
89  'header_css_class' => 'col-product',
90  'column_css_class' => 'col-product'
91  ]
92  );
93 
94  $currencyCode = $this->getCurrentCurrencyCode();
95 
96  $this->addColumn(
97  'price',
98  [
99  'header' => __('Price'),
100  'type' => 'currency',
101  'currency_code' => $currencyCode,
102  'index' => 'price',
103  'sortable' => false,
104  'renderer' => \Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency::class,
105  'rate' => $this->getRate($currencyCode),
106  'header_css_class' => 'col-price',
107  'column_css_class' => 'col-price'
108  ]
109  );
110 
111  $this->addColumn(
112  'carts',
113  [
114  'header' => __('Carts'),
115  'align' => 'right',
116  'index' => 'carts',
117  'sortable' => false,
118  'header_css_class' => 'col-carts',
119  'column_css_class' => 'col-carts'
120  ]
121  );
122 
123  $this->addColumn(
124  'orders',
125  [
126  'header' => __('Orders'),
127  'align' => 'right',
128  'index' => 'orders',
129  'sortable' => false,
130  'header_css_class' => 'col-qty',
131  'column_css_class' => 'col-qty'
132  ]
133  );
134 
135  $this->setFilterVisibility(false);
136 
137  $this->addExportType('*/*/exportProductCsv', __('CSV'));
138  $this->addExportType('*/*/exportProductExcel', __('Excel XML'));
139 
140  return parent::_prepareColumns();
141  }
142 
148  public function getRowUrl($row)
149  {
150  return $this->getUrl('catalog/product/edit', ['id' => $row->getProductId()]);
151  }
152 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Quote\Model\QueryResolver $queryResolver, \Magento\Reports\Model\ResourceModel\Quote\Item\CollectionFactory $quoteItemCollectionFactory, array $data=[])
Definition: Grid.php:33