Skip to content

Commit 17371a7

Browse files
committed
MC-42831: [Magento Cloud] Continuation from previous JIRA - "Add configured_variant to ConfigurableCartItem There is a PR and an MC"
1 parent ab59159 commit 17371a7

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

app/code/Magento/Catalog/Model/Attribute/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function __construct(\Magento\Catalog\Model\Attribute\Config\Data $dataSt
2828
* @param string $groupName Name of an attribute group
2929
* @return array
3030
*/
31-
public function getAttributeNames($groupName)
31+
public function getAttributeNames($groupName): array
3232
{
33-
return $this->_dataStorage->get($groupName, []);
33+
return (array) $this->_dataStorage->get($groupName, []);
3434
}
3535
}

app/code/Magento/Quote/Model/Quote/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(\Magento\Catalog\Model\Attribute\Config $attributeCo
2323
/**
2424
* @return array
2525
*/
26-
public function getProductAttributes()
26+
public function getProductAttributes(): array
2727
{
2828
return $this->_attributeConfig->getAttributeNames('quote_item');
2929
}
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\QuoteGraphQl\Plugin;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
11+
use Magento\Eav\Api\Data\AttributeInterface;
12+
use Magento\Framework\GraphQl\Query\Fields;
13+
use Magento\Quote\Model\Quote\Config as QuoteConfig;
14+
15+
class ProductAttributesExtender
16+
{
17+
/**
18+
* @var Fields
19+
*/
20+
private $fields;
21+
22+
/**
23+
* @var AttributeCollectionFactory
24+
*/
25+
private $attributeCollectionFactory;
26+
27+
/**
28+
* @param Fields $fields
29+
* @param AttributeCollectionFactory $attributeCollectionFactory
30+
*/
31+
public function __construct(
32+
Fields $fields,
33+
AttributeCollectionFactory $attributeCollectionFactory
34+
) {
35+
$this->fields = $fields;
36+
$this->attributeCollectionFactory = $attributeCollectionFactory;
37+
}
38+
39+
/**
40+
* @param QuoteConfig $subject
41+
* @param array $result
42+
* @return array
43+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
44+
*/
45+
public function afterGetProductAttributes(QuoteConfig $subject, array $result): array
46+
{
47+
$attributeCollection = $this->attributeCollectionFactory->create()
48+
->removeAllFieldsFromSelect()
49+
->addFieldToSelect(AttributeInterface::ATTRIBUTE_CODE)
50+
->setCodeFilter($this->fields->getFieldsUsedInQuery())
51+
->load();
52+
$attributes = $attributeCollection->getColumnValues(AttributeInterface::ATTRIBUTE_CODE);
53+
54+
return array_merge($result, $attributes);
55+
}
56+
}

app/code/Magento/QuoteGraphQl/etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@
2020
</argument>
2121
</arguments>
2222
</type>
23+
<type name="Magento\Quote\Model\Quote\Config">
24+
<plugin name="append_requested_graphql_attributes" type="Magento\QuoteGraphQl\Plugin\ProductAttributesExtender"/>
25+
</type>
2326
</config>

0 commit comments

Comments
 (0)