-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6395 from magento-l3/MC-38995-final
[l3] MC-38995: Customer group price is not working in product query graphql
- Loading branch information
Showing
7 changed files
with
323 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Model\Group; | ||
|
||
use Magento\Customer\Model\ResourceModel\Group\Resolver as ResolverResource; | ||
|
||
/** | ||
* Lightweight service for getting current customer group based on customer id | ||
*/ | ||
class Resolver | ||
{ | ||
/** | ||
* @var ResolverResource | ||
*/ | ||
private $resolverResource; | ||
|
||
/** | ||
* @param ResolverResource $resolverResource | ||
*/ | ||
public function __construct(ResolverResource $resolverResource) | ||
{ | ||
$this->resolverResource = $resolverResource; | ||
} | ||
|
||
/** | ||
* Return customer group id | ||
* | ||
* @param int $customerId | ||
* @return int|null | ||
*/ | ||
public function resolve(int $customerId) : ?int | ||
{ | ||
return $this->resolverResource->resolve($customerId); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/code/Magento/Customer/Model/ResourceModel/Group/Resolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Model\ResourceModel\Group; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
|
||
/** | ||
* Resource model for customer group resolver service | ||
*/ | ||
class Resolver | ||
{ | ||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @param ResourceConnection $resourceConnection | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resourceConnection | ||
) { | ||
$this->resourceConnection = $resourceConnection; | ||
} | ||
|
||
/** | ||
* Resolve customer group from db | ||
* | ||
* @param int $customerId | ||
* @return int|null | ||
*/ | ||
public function resolve(int $customerId) : ?int | ||
{ | ||
$result = null; | ||
|
||
$connection = $this->resourceConnection->getConnection(); | ||
$tableName = $this->resourceConnection->getTableName('customer_entity'); | ||
|
||
$query = $connection | ||
->select() | ||
->from( | ||
['main_table' => $tableName], | ||
['main_table.group_id'] | ||
) | ||
->where('main_table.entity_id = ?', $customerId); | ||
$groupId = $connection->fetchOne($query); | ||
if ($groupId) { | ||
$result = (int) $groupId; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/code/Magento/CustomerGraphQl/Model/Context/AddCustomerGroupToContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CustomerGraphQl\Model\Context; | ||
|
||
use Magento\Authorization\Model\UserContextInterface; | ||
use Magento\GraphQl\Model\Query\ContextParametersInterface; | ||
use Magento\GraphQl\Model\Query\ContextParametersProcessorInterface; | ||
use Magento\Customer\Model\Group; | ||
use Magento\Customer\Model\Group\Resolver as CustomerGroupResolver; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class AddCustomerGroupToContext implements ContextParametersProcessorInterface | ||
{ | ||
/** | ||
* @var CustomerGroupResolver | ||
*/ | ||
private $customerGroupResolver; | ||
|
||
/** | ||
* @param CustomerGroupResolver $customerGroupResolver | ||
*/ | ||
public function __construct( | ||
CustomerGroupResolver $customerGroupResolver | ||
) { | ||
$this->customerGroupResolver = $customerGroupResolver; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(ContextParametersInterface $contextParameters): ContextParametersInterface | ||
{ | ||
$customerGroupId = null; | ||
$extensionAttributes = $contextParameters->getExtensionAttributesData(); | ||
if ($contextParameters->getUserType() === UserContextInterface::USER_TYPE_GUEST) { | ||
$customerGroupId = Group::NOT_LOGGED_IN_ID; | ||
} elseif (!empty($extensionAttributes) && $extensionAttributes['is_customer'] === true) { | ||
$customerGroupId = $this->customerGroupResolver->resolve((int) $contextParameters->getUserId()); | ||
} | ||
if ($customerGroupId !== null) { | ||
$contextParameters->addExtensionAttribute('customer_group_id', (int) $customerGroupId); | ||
} | ||
return $contextParameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.