Skip to content

Commit 4539b37

Browse files
author
Oleksandr Iegorov
committed
MC-38995: Customer group price is not working in product query graphql
1 parent 74707e5 commit 4539b37

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface;
12+
use Magento\Framework\Api\SearchCriteriaInterface;
13+
use Magento\GraphQl\Model\Query\ContextInterface;
14+
15+
/**
16+
* Add price data to product collection results
17+
*/
18+
class PriceDataProcessor implements CollectionProcessorInterface
19+
{
20+
/**
21+
* Process to add price data to product collection.
22+
*
23+
* @param Collection $collection
24+
* @param SearchCriteriaInterface $searchCriteria
25+
* @param array $attributeNames
26+
* @param ContextInterface|null $context
27+
* @return Collection
28+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
29+
*/
30+
public function process(
31+
Collection $collection,
32+
SearchCriteriaInterface $searchCriteria,
33+
array $attributeNames,
34+
?ContextInterface $context = null
35+
): Collection {
36+
if ($context) {
37+
$customerGroupId = $context->getExtensionAttributes()->getCustomerGroupId();
38+
if ($customerGroupId !== null) {
39+
$collection->addPriceData($customerGroupId);
40+
}
41+
}
42+
43+
return $collection;
44+
}
45+
}

app/code/Magento/CatalogGraphQl/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<item name="stock" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor\StockProcessor</item>
5252
<item name="visibility" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor\VisibilityStatusProcessor</item>
5353
<item name="mediaGallery" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor\MediaGalleryProcessor</item>
54+
<item name="priceData" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor\PriceDataProcessor</item>
5455
</argument>
5556
</arguments>
5657
</type>

app/code/Magento/CustomerGraphQl/Model/Context/AddCustomerGroupToContext.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Authorization\Model\UserContextInterface;
1111
use Magento\GraphQl\Model\Query\ContextParametersInterface;
1212
use Magento\GraphQl\Model\Query\ContextParametersProcessorInterface;
13-
use Magento\Customer\Model\Session as CustomerSession;
1413
use Magento\Customer\Model\Group;
1514
use Magento\Customer\Api\CustomerRepositoryInterface;
1615
use Magento\Framework\Exception\LocalizedException;
@@ -20,25 +19,17 @@
2019
*/
2120
class AddCustomerGroupToContext implements ContextParametersProcessorInterface
2221
{
23-
/**
24-
* @var CustomerSession
25-
*/
26-
private $customerSession;
27-
2822
/**
2923
* @var CustomerRepositoryInterface
3024
*/
3125
private $customerRepository;
3226

3327
/**
34-
* @param CustomerSession $customerSession
3528
* @param CustomerRepositoryInterface $customerRepository
3629
*/
3730
public function __construct(
38-
CustomerSession $customerSession,
3931
CustomerRepositoryInterface $customerRepository
4032
) {
41-
$this->customerSession = $customerSession;
4233
$this->customerRepository = $customerRepository;
4334
}
4435

@@ -47,7 +38,6 @@ public function __construct(
4738
*/
4839
public function execute(ContextParametersInterface $contextParameters): ContextParametersInterface
4940
{
50-
$customerSession = $this->customerSession;
5141
$customerGroupId = null;
5242
$extensionAttributes = $contextParameters->getExtensionAttributesData();
5343
if ($contextParameters->getUserType() === UserContextInterface::USER_TYPE_GUEST) {
@@ -61,7 +51,6 @@ public function execute(ContextParametersInterface $contextParameters): ContextP
6151
}
6252
}
6353
if ($customerGroupId !== null) {
64-
$customerSession->setCustomerGroupId($customerGroupId);
6554
$contextParameters->addExtensionAttribute('customer_group_id', (int) $customerGroupId);
6655
}
6756
return $contextParameters;

0 commit comments

Comments
 (0)