Files
magento2/app/code/Magento/QuoteGraphQl/Plugin/ProductAttributesExtender.php
Rafal JanickiandSergii Ivashchenko 79d57b4eb7 Storefront GraphQl Enhancements
* LYNX-145: Add options to item's product data in cart

* LYNX-145: Refactring

* LYNX-145: Tests refactoring

* LYNX-145: Refactoring - CR changes

* LYNX-145: Refactoring - CR changes

* LYNX-145: Fix static tests

* LYNX-145: Added _resetState() for product attributes

* LYNX-145: Refactoring

* LYNX-145: Refactoring

* LYNX-337: Add sorting parameter to products in the cart

* LYNX-337: Refactoring

* LYNX-337: Refactoring

* LYNX-337: Base test case

* LYNX-337: WepAPI tests coverage

* LYNX-337: Pre-CR refactoring

* LYNX-337: Refactoring; fix static tests

* LYNX-354: Update estimateShippingMethods GraphQl schema

* LYNX-354: Refactoring; bugfixing;

* LYNX-354: Tests refactoring

* LYNX-354: pre-CR changes

* LYNX-336: Multicoupon

* LYNX-354: CR changes

* LYNX-354: CR changes

* LYNX-337: CR refactoring

* LYNX-337: Update tests

---------

Co-authored-by: Sergii Ivashchenko <serg.ivashchenko@gmail.com>
2024-02-16 13:54:15 +00:00

64 lines
1.8 KiB
PHP

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\QuoteGraphQl\Plugin;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
use Magento\Framework\GraphQl\Query\Fields;
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
use Magento\Quote\Model\Quote\Config as QuoteConfig;
/**
* Class for extending product attributes for quote.
*/
class ProductAttributesExtender implements ResetAfterRequestInterface
{
/**
* @var array
*/
private $attributes;
/**
* @param Fields $fields
* @param AttributeCollectionFactory $attributeCollectionFactory
*/
public function __construct(
private Fields $fields,
private AttributeCollectionFactory $attributeCollectionFactory,
) {
}
/**
* Add requested product attributes.
*
* @param QuoteConfig $subject
* @param array $result
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetProductAttributes(QuoteConfig $subject, array $result): array
{
if (!$this->attributes) {
$attributeCollection = $this->attributeCollectionFactory->create()
->removeAllFieldsFromSelect()
->addFieldToSelect('attribute_code')
->setCodeFilter($this->fields->getFieldsUsedInQuery())
->load();
$this->attributes = $attributeCollection->getColumnValues('attribute_code');
}
return array_unique(array_merge($result, $this->attributes));
}
/**
* @inheritDoc
*/
public function _resetState(): void
{
$this->attributes = [];
}
}