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
*
11
15
* @api
12
16
* @author Magento Core Team <[email protected] >
13
17
* @since 100.0.2
18
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
19
*/
15
20
class Grid extends \Magento \Backend \Block \Widget \Grid \Extended
16
21
{
@@ -42,6 +47,11 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
42
47
*/
43
48
protected $ _productFactory ;
44
49
50
+ /**
51
+ * @var ProductCollectionDataProvider $productCollectionProvider
52
+ */
53
+ private $ productCollectionProvider ;
54
+
45
55
/**
46
56
* @param \Magento\Backend\Block\Template\Context $context
47
57
* @param \Magento\Backend\Helper\Data $backendHelper
@@ -50,6 +60,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
50
60
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
51
61
* @param \Magento\Sales\Model\Config $salesConfig
52
62
* @param array $data
63
+ * @param ProductCollectionDataProvider|null $productCollectionProvider
53
64
*/
54
65
public function __construct (
55
66
\Magento \Backend \Block \Template \Context $ context ,
@@ -58,12 +69,15 @@ public function __construct(
58
69
\Magento \Catalog \Model \Config $ catalogConfig ,
59
70
\Magento \Backend \Model \Session \Quote $ sessionQuote ,
60
71
\Magento \Sales \Model \Config $ salesConfig ,
61
- array $ data = []
72
+ array $ data = [],
73
+ ProductCollectionDataProvider $ productCollectionProvider = null
62
74
) {
63
75
$ this ->_productFactory = $ productFactory ;
64
76
$ this ->_catalogConfig = $ catalogConfig ;
65
77
$ this ->_sessionQuote = $ sessionQuote ;
66
78
$ this ->_salesConfig = $ salesConfig ;
79
+ $ this ->productCollectionProvider = $ productCollectionProvider
80
+ ?: ObjectManager::getInstance ()->get (ProductCollectionDataProvider::class);
67
81
parent ::__construct ($ context , $ backendHelper , $ data );
68
82
}
69
83
@@ -140,20 +154,18 @@ protected function _addColumnFilterToCollection($column)
140
154
*/
141
155
protected function _prepareCollection ()
142
156
{
157
+
143
158
$ attributes = $ this ->_catalogConfig ->getProductAttributes ();
159
+ $ store = $ this ->getStore ();
160
+
144
161
/* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
145
- $ collection = $ this ->_productFactory ->create ()->getCollection ();
146
- $ collection ->setStore (
147
- $ this ->getStore ()
148
- )->addAttributeToSelect (
162
+ $ collection = $ this ->productCollectionProvider ->getCollectionForStore ($ store );
163
+ $ collection ->addAttributeToSelect (
149
164
$ attributes
150
- )->addAttributeToSelect (
151
- 'sku '
152
- )->addStoreFilter ()->addAttributeToFilter (
165
+ );
166
+ $ collection ->addAttributeToFilter (
153
167
'type_id ' ,
154
168
$ this ->_salesConfig ->getAvailableProductTypes ()
155
- )->addAttributeToSelect (
156
- 'gift_message_available '
157
169
);
158
170
159
171
$ this ->setCollection ($ collection );
0 commit comments