Skip to content

Commit

Permalink
ENGCOM-3611: Set view models as shareable by default #18541
Browse files Browse the repository at this point in the history
 - Merge Pull Request #18541 from thomas-kl1/magento2:patch/layout-block-argument-shareable
 - Merged commits:
   1. 9a7f3e6
   2. 415288f
   3. 32f2813
   4. 02d475c
   5. 3959725
  • Loading branch information
magento-engcom-team committed Apr 11, 2019
2 parents ff6d03c + 3959725 commit bf7cea3
Show file tree
Hide file tree
Showing 4 changed files with 562 additions and 23 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 <core@magentocommerce.com>
* @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;
}
}
8 changes: 7 additions & 1 deletion lib/internal/Magento/Framework/View/Layout/etc/elements.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
<xs:sequence>
<xs:element name="updater" type="updaterType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="shared" type="xs:boolean" default="true" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="object">
<xs:complexContent>
<xs:extension base="argumentType">
<xs:attribute name="shared" use="optional" type="xs:boolean"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Expand Down
Loading

0 comments on commit bf7cea3

Please sign in to comment.