14
14
use Magento \Backend \Block \Widget \Grid ;
15
15
use Magento \Backend \Block \Widget \Grid \Column ;
16
16
use Magento \Backend \Block \Widget \Grid \Extended ;
17
+ use Magento \Catalog \Model \Product \Attribute \Source \Status ;
18
+ use Magento \Catalog \Model \Product \Visibility ;
19
+ use Magento \Framework \App \ObjectManager ;
17
20
18
21
class Product extends \Magento \Backend \Block \Widget \Grid \Extended
19
22
{
@@ -29,22 +32,38 @@ class Product extends \Magento\Backend\Block\Widget\Grid\Extended
29
32
*/
30
33
protected $ _productFactory ;
31
34
35
+ /**
36
+ * @var Status
37
+ */
38
+ private $ status ;
39
+
40
+ /**
41
+ * @var Visibility
42
+ */
43
+ private $ visibility ;
44
+
32
45
/**
33
46
* @param \Magento\Backend\Block\Template\Context $context
34
47
* @param \Magento\Backend\Helper\Data $backendHelper
35
48
* @param \Magento\Catalog\Model\ProductFactory $productFactory
36
49
* @param \Magento\Framework\Registry $coreRegistry
37
50
* @param array $data
51
+ * @param Visibility|null $visibility
52
+ * @param Status|null $status
38
53
*/
39
54
public function __construct (
40
55
\Magento \Backend \Block \Template \Context $ context ,
41
56
\Magento \Backend \Helper \Data $ backendHelper ,
42
57
\Magento \Catalog \Model \ProductFactory $ productFactory ,
43
58
\Magento \Framework \Registry $ coreRegistry ,
44
- array $ data = []
59
+ array $ data = [],
60
+ Visibility $ visibility = null ,
61
+ Status $ status = null
45
62
) {
46
63
$ this ->_productFactory = $ productFactory ;
47
64
$ this ->_coreRegistry = $ coreRegistry ;
65
+ $ this ->visibility = $ visibility ?: ObjectManager::getInstance ()->get (Visibility::class);
66
+ $ this ->status = $ status ?: ObjectManager::getInstance ()->get (Status::class);
48
67
parent ::__construct ($ context , $ backendHelper , $ data );
49
68
}
50
69
@@ -102,6 +121,10 @@ protected function _prepareCollection()
102
121
'name '
103
122
)->addAttributeToSelect (
104
123
'sku '
124
+ )->addAttributeToSelect (
125
+ 'visibility '
126
+ )->addAttributeToSelect (
127
+ 'status '
105
128
)->addAttributeToSelect (
106
129
'price '
107
130
)->joinField (
@@ -159,6 +182,28 @@ protected function _prepareColumns()
159
182
);
160
183
$ this ->addColumn ('name ' , ['header ' => __ ('Name ' ), 'index ' => 'name ' ]);
161
184
$ this ->addColumn ('sku ' , ['header ' => __ ('SKU ' ), 'index ' => 'sku ' ]);
185
+ $ this ->addColumn (
186
+ 'visibility ' ,
187
+ [
188
+ 'header ' => __ ('Visibility ' ),
189
+ 'index ' => 'visibility ' ,
190
+ 'type ' => 'options ' ,
191
+ 'options ' => $ this ->visibility ->getOptionArray (),
192
+ 'header_css_class ' => 'col-visibility ' ,
193
+ 'column_css_class ' => 'col-visibility '
194
+ ]
195
+ );
196
+
197
+ $ this ->addColumn (
198
+ 'status ' ,
199
+ [
200
+ 'header ' => __ ('Status ' ),
201
+ 'index ' => 'status ' ,
202
+ 'type ' => 'options ' ,
203
+ 'options ' => $ this ->status ->getOptionArray ()
204
+ ]
205
+ );
206
+
162
207
$ this ->addColumn (
163
208
'price ' ,
164
209
[
0 commit comments