5
5
*/
6
6
namespace Magento \Sales \Block \Adminhtml \Order \Create \Search ;
7
7
8
+ use Magento \Sales \Block \Adminhtml \Order \Create \Search \Grid \DataProvider \ProductCollection
9
+ as ProductCollectionDataProvider ;
10
+ use Magento \Framework \App \ObjectManager ;
11
+
8
12
/**
9
13
* Adminhtml sales order create search products block
10
14
*
@@ -42,6 +46,11 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
42
46
*/
43
47
protected $ _productFactory ;
44
48
49
+ /**
50
+ * @var ProductCollectionDataProvider $productCollectionProvider
51
+ */
52
+ private $ productCollectionProvider ;
53
+
45
54
/**
46
55
* @param \Magento\Backend\Block\Template\Context $context
47
56
* @param \Magento\Backend\Helper\Data $backendHelper
@@ -50,6 +59,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
50
59
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
51
60
* @param \Magento\Sales\Model\Config $salesConfig
52
61
* @param array $data
62
+ * @param ProductCollectionDataProvider|null $productCollectionProvider
53
63
*/
54
64
public function __construct (
55
65
\Magento \Backend \Block \Template \Context $ context ,
@@ -58,12 +68,15 @@ public function __construct(
58
68
\Magento \Catalog \Model \Config $ catalogConfig ,
59
69
\Magento \Backend \Model \Session \Quote $ sessionQuote ,
60
70
\Magento \Sales \Model \Config $ salesConfig ,
61
- array $ data = []
71
+ array $ data = [],
72
+ ProductCollectionDataProvider $ productCollectionProvider = null
62
73
) {
63
74
$ this ->_productFactory = $ productFactory ;
64
75
$ this ->_catalogConfig = $ catalogConfig ;
65
76
$ this ->_sessionQuote = $ sessionQuote ;
66
77
$ this ->_salesConfig = $ salesConfig ;
78
+ $ this ->productCollectionProvider = $ productCollectionProvider
79
+ ?: ObjectManager::getInstance ()->get (ProductCollectionDataProvider::class);
67
80
parent ::__construct ($ context , $ backendHelper , $ data );
68
81
}
69
82
@@ -140,8 +153,21 @@ protected function _addColumnFilterToCollection($column)
140
153
*/
141
154
protected function _prepareCollection ()
142
155
{
156
+
143
157
$ attributes = $ this ->_catalogConfig ->getProductAttributes ();
158
+ $ store = $ this ->getStore ();
159
+
144
160
/* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
161
+ $ collection = $ this ->productCollectionProvider ->getCollectionForStore ($ store );
162
+ $ collection ->addAttributeToSelect (
163
+ $ attributes
164
+ );
165
+ $ collection ->addAttributeToFilter (
166
+ 'type_id ' ,
167
+ $ this ->_salesConfig ->getAvailableProductTypes ()
168
+ );
169
+
170
+ /*
145
171
$collection = $this->_productFactory->create()->getCollection();
146
172
$collection->setStore(
147
173
$this->getStore()
@@ -155,6 +181,7 @@ protected function _prepareCollection()
155
181
)->addAttributeToSelect(
156
182
'gift_message_available'
157
183
);
184
+ */
158
185
159
186
$ this ->setCollection ($ collection );
160
187
return parent ::_prepareCollection ();
0 commit comments