Skip to content

Commit

Permalink
Merge pull request #4024 from magento-tango/MAGETWO-98831
Browse files Browse the repository at this point in the history
[tango] MAGETWO-98831: The SKU was not found in the catalog
  • Loading branch information
dhorytskyi authored Apr 10, 2019
2 parents ab188bc + 5008e85 commit aec044d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 10 deletions.
32 changes: 22 additions & 10 deletions app/code/Magento/Sales/Block/Adminhtml/Order/Create/Search/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
*/
namespace Magento\Sales\Block\Adminhtml\Order\Create\Search;

use Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\DataProvider\ProductCollection
as ProductCollectionDataProvider;
use Magento\Framework\App\ObjectManager;

/**
* Adminhtml sales order create search products block
*
* @api
* @author Magento Core Team <[email protected]>
* @since 100.0.2
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
{
Expand Down Expand Up @@ -42,6 +47,11 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
*/
protected $_productFactory;

/**
* @var ProductCollectionDataProvider $productCollectionProvider
*/
private $productCollectionProvider;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
Expand All @@ -50,6 +60,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
* @param \Magento\Sales\Model\Config $salesConfig
* @param array $data
* @param ProductCollectionDataProvider|null $productCollectionProvider
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
Expand All @@ -58,12 +69,15 @@ public function __construct(
\Magento\Catalog\Model\Config $catalogConfig,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\Config $salesConfig,
array $data = []
array $data = [],
ProductCollectionDataProvider $productCollectionProvider = null
) {
$this->_productFactory = $productFactory;
$this->_catalogConfig = $catalogConfig;
$this->_sessionQuote = $sessionQuote;
$this->_salesConfig = $salesConfig;
$this->productCollectionProvider = $productCollectionProvider
?: ObjectManager::getInstance()->get(ProductCollectionDataProvider::class);
parent::__construct($context, $backendHelper, $data);
}

Expand Down Expand Up @@ -140,20 +154,18 @@ protected function _addColumnFilterToCollection($column)
*/
protected function _prepareCollection()
{

$attributes = $this->_catalogConfig->getProductAttributes();
$store = $this->getStore();

/* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
$collection = $this->_productFactory->create()->getCollection();
$collection->setStore(
$this->getStore()
)->addAttributeToSelect(
$collection = $this->productCollectionProvider->getCollectionForStore($store);
$collection->addAttributeToSelect(
$attributes
)->addAttributeToSelect(
'sku'
)->addStoreFilter()->addAttributeToFilter(
);
$collection->addAttributeToFilter(
'type_id',
$this->_salesConfig->getAvailableProductTypes()
)->addAttributeToSelect(
'gift_message_available'
);

$this->setCollection($collection);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\DataProvider;

use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Store\Model\Store;

/**
* Prepares product collection for the grid
*/
class ProductCollection
{
/**
* @var ProductCollectionFactory
*/
private $collectionFactory;

/**
* @param ProductCollectionFactory $collectionFactory
*/
public function __construct(
ProductCollectionFactory $collectionFactory
) {
$this->collectionFactory = $collectionFactory;
}

/**
* Provide products collection filtered with store
*
* @param Store $store
* @return Collection
*/
public function getCollectionForStore(Store $store):Collection
{
/** @var Collection $collection */
$collection = $this->collectionFactory->create();

$collection->setStore($store);
$collection->addAttributeToSelect(
'gift_message_available'
);
$collection->addAttributeToSelect(
'sku'
);
$collection->addStoreFilter();

return $collection;
}
}

0 comments on commit aec044d

Please sign in to comment.