-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4024 from magento-tango/MAGETWO-98831
[tango] MAGETWO-98831: The SKU was not found in the catalog
- Loading branch information
Showing
2 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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 | ||
|
@@ -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, | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
|
55 changes: 55 additions & 0 deletions
55
...Magento/Sales/Block/Adminhtml/Order/Create/Search/Grid/DataProvider/ProductCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |