Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit f369824

Browse files
committed
[EngCom] Public Pull Requests - develop
- merged latest code from mainline branch
2 parents 48acb90 + cf85308 commit f369824

File tree

111 files changed

+4411
-1688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4411
-1688
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable/Attribute/Collection.php

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
99

10+
use Magento\Catalog\Model\Product;
1011
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute as Model;
1113
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
1214
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable as ConfigurableResource;
1315
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
@@ -39,6 +41,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
3941
* Product instance
4042
*
4143
* @var \Magento\Catalog\Model\Product
44+
* @deprecated Now collection supports fetching options for multiple products. This field will be set to first
45+
* element of products array.
4246
*/
4347
protected $_product;
4448

@@ -68,6 +72,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
6872
*/
6973
private $metadataPool;
7074

75+
/**
76+
* @var \Magento\Catalog\Model\Product[]
77+
*/
78+
private $products;
79+
7180
/**
7281
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
7382
* @param \Psr\Log\LoggerInterface $logger
@@ -122,9 +131,10 @@ protected function _construct()
122131
*/
123132
public function setProductFilter($product)
124133
{
125-
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
126-
$this->_product = $product;
127-
return $this->addFieldToFilter('product_id', $product->getData($metadata->getLinkField()));
134+
$this->products[] = $product;
135+
$this->_product = reset($this->products);
136+
137+
return $this;
128138
}
129139

130140
/**
@@ -156,7 +166,24 @@ public function orderByPosition($dir = self::SORT_ORDER_ASC)
156166
*/
157167
public function getStoreId()
158168
{
159-
return (int)$this->_product->getStoreId();
169+
return reset($this->products)->getStoreId();
170+
}
171+
172+
/**
173+
* Add product ids to `in` filter before load
174+
*
175+
* @return $this
176+
* @throws \Exception
177+
*/
178+
protected function _beforeLoad()
179+
{
180+
parent::_beforeLoad();
181+
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
182+
$productIds = [];
183+
foreach ($this->products as $product) {
184+
$productIds[] = $product->getData($metadata->getLinkField());
185+
}
186+
return $this->addFieldToFilter('product_id', ['in (?)' => $productIds]);
160187
}
161188

162189
/**
@@ -186,16 +213,34 @@ protected function _afterLoad()
186213
*/
187214
protected function _addProductAttributes()
188215
{
216+
/** @var Model $item */
189217
foreach ($this->_items as $item) {
190218
$productAttribute = $this->getProductType()->getAttributeById(
191219
$item->getAttributeId(),
192-
$this->getProduct()
220+
$this->getAttributeParentProduct($item)
193221
);
194222
$item->setProductAttribute($productAttribute);
195223
}
196224
return $this;
197225
}
198226

227+
/**
228+
* Get product that has given attribute
229+
*
230+
* @param Model $attribute
231+
* @return Product
232+
*/
233+
private function getAttributeParentProduct($attribute)
234+
{
235+
$targetProduct = null;
236+
foreach ($this->products as $product) {
237+
if ($product->getId() === $attribute->getProductId()) {
238+
$targetProduct = $product;
239+
}
240+
}
241+
return $targetProduct ?: reset($this->products);
242+
}
243+
199244
/**
200245
* Add Associated Product Filters (From Product Type Instance)
201246
*
@@ -204,10 +249,12 @@ protected function _addProductAttributes()
204249
*/
205250
public function _addAssociatedProductFilters()
206251
{
207-
$this->getProductType()->getUsedProducts(
208-
$this->getProduct(),
209-
$this->getColumnValues('attribute_id') // Filter associated products
210-
);
252+
foreach ($this->products as $product) {
253+
$this->getProductType()->getUsedProducts(
254+
$product,
255+
$this->getColumnValues('attribute_id') // Filter associated products
256+
);
257+
}
211258
return $this;
212259
}
213260

@@ -261,6 +308,7 @@ protected function loadOptions()
261308
{
262309
/** @var ConfigurableResource $configurableResource */
263310
$configurableResource = $this->getConfigurableResource();
311+
/** @var Model $item */
264312
foreach ($this->_items as $item) {
265313
$values = [];
266314

@@ -269,9 +317,7 @@ protected function loadOptions()
269317
$itemId = $item->getId();
270318
$options = $configurableResource->getAttributeOptions(
271319
$productAttribute,
272-
$this->getProduct()->getData(
273-
$this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField()
274-
)
320+
$item->getProductId()
275321
);
276322
foreach ($options as $option) {
277323
$values[$itemId . ':' . $option['value_index']] = [
@@ -305,16 +351,6 @@ protected function getIncludedOptions(array $usedProducts, AbstractAttribute $pr
305351
return $options;
306352
}
307353

308-
/**
309-
* Retrieve product instance
310-
*
311-
* @return \Magento\Catalog\Model\Product
312-
*/
313-
private function getProduct()
314-
{
315-
return $this->_product;
316-
}
317-
318354
/**
319355
* @inheritdoc
320356
* @since 100.0.6

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable/Product/Collection.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
2323
*/
2424
protected $_linkTable;
2525

26+
/**
27+
* @var \Magento\Catalog\Model\Product[]
28+
*/
29+
private $products;
30+
2631
/**
2732
* Assign link table name
2833
*
@@ -59,9 +64,26 @@ protected function _initSelect()
5964
*/
6065
public function setProductFilter($product)
6166
{
67+
$this->products[] = $product;
68+
return $this;
69+
}
70+
71+
/**
72+
* Add parent ids to `in` filter before load.
73+
*
74+
* @return $this
75+
*/
76+
protected function _beforeLoad()
77+
{
78+
parent::_beforeLoad();
6279
$metadata = $this->getProductEntityMetadata();
80+
$parentIds = [];
81+
foreach ($this->products as $product) {
82+
$parentIds[] = $product->getData($metadata->getLinkField());
83+
}
84+
85+
$this->getSelect()->where('link_table.parent_id in (?)', $parentIds);
6386

64-
$this->getSelect()->where('link_table.parent_id = ?', $product->getData($metadata->getLinkField()));
6587
return $this;
6688
}
6789

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Authorization\Model\CompositeUserContext">
10+
<arguments>
11+
<argument name="userContexts" xsi:type="array">
12+
<item name="customerSessionUserContext" xsi:type="array">
13+
<item name="type" xsi:type="object">Magento\Customer\Model\Authorization\CustomerSessionUserContext</item>
14+
<item name="sortOrder" xsi:type="string">20</item>
15+
</item>
16+
</argument>
17+
</arguments>
18+
</type>
19+
</config>

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\GraphQl\Controller;
88

99
use Magento\Framework\App\FrontControllerInterface;
10+
use Magento\Framework\App\Request\Http;
1011
use Magento\Framework\App\RequestInterface;
1112
use Magento\Framework\App\ResponseInterface;
1213
use Magento\Framework\Exception\LocalizedException;
@@ -15,6 +16,7 @@
1516
use Magento\GraphQl\Model\SchemaGeneratorInterface;
1617
use Magento\Framework\GraphQl\RequestProcessor;
1718
use Magento\Framework\GraphQl\ExceptionFormatter;
19+
use Magento\GraphQl\Model\ResolverContext;
1820

1921
/**
2022
* Front controller for web API GraphQL area.
@@ -44,25 +46,31 @@ class GraphQl implements FrontControllerInterface
4446
/** @var ExceptionFormatter */
4547
private $graphQlError;
4648

49+
/** @var ResolverContext */
50+
private $context;
51+
4752
/**
4853
* @param Response $response
4954
* @param SchemaGeneratorInterface $schemaGenerator
5055
* @param SerializerInterface $jsonSerializer
5156
* @param RequestProcessor $requestProcessor
5257
* @param ExceptionFormatter $graphQlError
58+
* @param ResolverContext $context
5359
*/
5460
public function __construct(
5561
Response $response,
5662
SchemaGeneratorInterface $schemaGenerator,
5763
SerializerInterface $jsonSerializer,
5864
RequestProcessor $requestProcessor,
59-
ExceptionFormatter $graphQlError
65+
ExceptionFormatter $graphQlError,
66+
ResolverContext $context
6067
) {
6168
$this->response = $response;
6269
$this->schemaGenerator = $schemaGenerator;
6370
$this->jsonSerializer = $jsonSerializer;
6471
$this->requestProcessor = $requestProcessor;
6572
$this->graphQlError = $graphQlError;
73+
$this->context = $context;
6674
}
6775

6876
/**
@@ -74,6 +82,7 @@ public function __construct(
7482
public function dispatch(RequestInterface $request)
7583
{
7684
try {
85+
/** @var $request Http */
7786
if ($request->getHeader('Content-Type')
7887
&& strpos($request->getHeader('Content-Type'), 'application/json') !== false
7988
) {
@@ -87,7 +96,7 @@ public function dispatch(RequestInterface $request)
8796
$schema,
8897
isset($data['query']) ? $data['query'] : '',
8998
null,
90-
null,
99+
$this->context,
91100
isset($data['variables']) ? $data['variables'] : []
92101
);
93102
} catch (\Exception $error) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQl\Model;
8+
9+
use Magento\Eav\Api\AttributeManagementInterface;
10+
use Magento\Eav\Setup\EavSetupFactory;
11+
use Magento\Eav\Setup\EavSetup;
12+
13+
class EntityAttributeList
14+
{
15+
/**
16+
* @var AttributeManagementInterface
17+
*/
18+
private $management;
19+
20+
/**
21+
* @var EavSetupFactory
22+
*/
23+
private $eavSetupFactory;
24+
25+
/**
26+
* @var EavSetup
27+
*/
28+
private $eavSetup;
29+
30+
/**
31+
* @param AttributeManagementInterface $management
32+
* @param EavSetupFactory $eavSetupFactory
33+
*/
34+
public function __construct(
35+
AttributeManagementInterface $management,
36+
EavSetupFactory $eavSetupFactory
37+
) {
38+
$this->management = $management;
39+
$this->eavSetupFactory = $eavSetupFactory;
40+
$this->eavSetup = $this->eavSetupFactory->create();
41+
}
42+
43+
public function getDefaultEntityAttributes(string $entityCode)
44+
{
45+
$defaultAttributeSetId = $this->eavSetup->getDefaultAttributeSetId($entityCode);
46+
return $this->management->getAttributes($entityCode, $defaultAttributeSetId);
47+
}
48+
}

0 commit comments

Comments
 (0)