Skip to content

Commit 92b0e8b

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-98831: The SKU was not found in the catalog
1 parent 2bca2aa commit 92b0e8b

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Search/Grid.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace 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
*
@@ -42,6 +46,11 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
4246
*/
4347
protected $_productFactory;
4448

49+
/**
50+
* @var ProductCollectionDataProvider $productCollectionProvider
51+
*/
52+
private $productCollectionProvider;
53+
4554
/**
4655
* @param \Magento\Backend\Block\Template\Context $context
4756
* @param \Magento\Backend\Helper\Data $backendHelper
@@ -50,6 +59,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
5059
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
5160
* @param \Magento\Sales\Model\Config $salesConfig
5261
* @param array $data
62+
* @param ProductCollectionDataProvider|null $productCollectionProvider
5363
*/
5464
public function __construct(
5565
\Magento\Backend\Block\Template\Context $context,
@@ -58,12 +68,15 @@ public function __construct(
5868
\Magento\Catalog\Model\Config $catalogConfig,
5969
\Magento\Backend\Model\Session\Quote $sessionQuote,
6070
\Magento\Sales\Model\Config $salesConfig,
61-
array $data = []
71+
array $data = [],
72+
ProductCollectionDataProvider $productCollectionProvider = null
6273
) {
6374
$this->_productFactory = $productFactory;
6475
$this->_catalogConfig = $catalogConfig;
6576
$this->_sessionQuote = $sessionQuote;
6677
$this->_salesConfig = $salesConfig;
78+
$this->productCollectionProvider = $productCollectionProvider
79+
?: ObjectManager::getInstance()->get(ProductCollectionDataProvider::class);
6780
parent::__construct($context, $backendHelper, $data);
6881
}
6982

@@ -140,8 +153,21 @@ protected function _addColumnFilterToCollection($column)
140153
*/
141154
protected function _prepareCollection()
142155
{
156+
143157
$attributes = $this->_catalogConfig->getProductAttributes();
158+
$store = $this->getStore();
159+
144160
/* @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+
/*
145171
$collection = $this->_productFactory->create()->getCollection();
146172
$collection->setStore(
147173
$this->getStore()
@@ -155,6 +181,7 @@ protected function _prepareCollection()
155181
)->addAttributeToSelect(
156182
'gift_message_available'
157183
);
184+
*/
158185

159186
$this->setCollection($collection);
160187
return parent::_prepareCollection();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\DataProvider;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
use Magento\Store\Model\Store;
13+
14+
/**
15+
* Prepares product collection for the grid
16+
*/
17+
class ProductCollection
18+
{
19+
/**
20+
* @var ProductCollectionFactory
21+
*/
22+
private $collectionFactory;
23+
24+
/**
25+
* @param ProductCollectionFactory $collectionFactory
26+
*/
27+
public function __construct(
28+
ProductCollectionFactory $collectionFactory
29+
) {
30+
$this->collectionFactory = $collectionFactory;
31+
}
32+
33+
/**
34+
* Provide products collection filtered with store
35+
*
36+
* @param Store $store
37+
* @return Collection
38+
*/
39+
public function getCollectionForStore(Store $store):Collection
40+
{
41+
/** @var Collection $collection */
42+
$collection = $this->collectionFactory->create();
43+
44+
$collection->setStore($store);
45+
$collection->addAttributeToSelect(
46+
'gift_message_available'
47+
);
48+
$collection->addAttributeToSelect(
49+
'sku'
50+
);
51+
$collection->addStoreFilter();
52+
53+
return $collection;
54+
}
55+
}
56+

0 commit comments

Comments
 (0)