55 */
66namespace Magento \Sales \Block \Adminhtml \Order \Create \Search ;
77
8+ use Magento \Sales \Block \Adminhtml \Order \Create \Search \Grid \DataProvider \ProductCollection
9+ as ProductCollectionDataProvider ;
10+ use Magento \Framework \App \ObjectManager ;
11+
812/**
913 * Adminhtml sales order create search products block
1014 *
1115 * @api
1216 * @author Magento Core Team <core@magentocommerce.com>
1317 * @since 100.0.2
18+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1419 */
1520class Grid extends \Magento \Backend \Block \Widget \Grid \Extended
1621{
@@ -42,6 +47,11 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
4247 */
4348 protected $ _productFactory ;
4449
50+ /**
51+ * @var ProductCollectionDataProvider $productCollectionProvider
52+ */
53+ private $ productCollectionProvider ;
54+
4555 /**
4656 * @param \Magento\Backend\Block\Template\Context $context
4757 * @param \Magento\Backend\Helper\Data $backendHelper
@@ -50,6 +60,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
5060 * @param \Magento\Backend\Model\Session\Quote $sessionQuote
5161 * @param \Magento\Sales\Model\Config $salesConfig
5262 * @param array $data
63+ * @param ProductCollectionDataProvider|null $productCollectionProvider
5364 */
5465 public function __construct (
5566 \Magento \Backend \Block \Template \Context $ context ,
@@ -58,12 +69,15 @@ public function __construct(
5869 \Magento \Catalog \Model \Config $ catalogConfig ,
5970 \Magento \Backend \Model \Session \Quote $ sessionQuote ,
6071 \Magento \Sales \Model \Config $ salesConfig ,
61- array $ data = []
72+ array $ data = [],
73+ ProductCollectionDataProvider $ productCollectionProvider = null
6274 ) {
6375 $ this ->_productFactory = $ productFactory ;
6476 $ this ->_catalogConfig = $ catalogConfig ;
6577 $ this ->_sessionQuote = $ sessionQuote ;
6678 $ this ->_salesConfig = $ salesConfig ;
79+ $ this ->productCollectionProvider = $ productCollectionProvider
80+ ?: ObjectManager::getInstance ()->get (ProductCollectionDataProvider::class);
6781 parent ::__construct ($ context , $ backendHelper , $ data );
6882 }
6983
@@ -140,20 +154,18 @@ protected function _addColumnFilterToCollection($column)
140154 */
141155 protected function _prepareCollection ()
142156 {
157+
143158 $ attributes = $ this ->_catalogConfig ->getProductAttributes ();
159+ $ store = $ this ->getStore ();
160+
144161 /* @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 (
149164 $ attributes
150- )->addAttributeToSelect (
151- 'sku '
152- )->addStoreFilter ()->addAttributeToFilter (
165+ );
166+ $ collection ->addAttributeToFilter (
153167 'type_id ' ,
154168 $ this ->_salesConfig ->getAvailableProductTypes ()
155- )->addAttributeToSelect (
156- 'gift_message_available '
157169 );
158170
159171 $ this ->setCollection ($ collection );
0 commit comments