diff -Nuar a/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/PriceRange.php b/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/PriceRange.php index dbb52f20109..0d91cfe0a26 100644 --- a/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/PriceRange.php +++ b/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/PriceRange.php @@ -62,6 +62,13 @@ class PriceRange implements ResolverInterface $product = $value['model']; $product->unsetData('minimal_price'); + if ($context) { + $customerGroupId = $context->getExtensionAttributes()->getCustomerGroupId(); + if ($customerGroupId !== null) { + $product->setCustomerGroupId($customerGroupId); + } + } + $requestedFields = $info->getFieldSelection(10); $returnArray = []; diff -Nuar a/vendor/magento/module-customer/Model/Group/Resolver.php b/vendor/magento/module-customer/Model/Group/Resolver.php new file mode 100644 index 00000000000..fd797d744e6 --- /dev/null +++ b/vendor/magento/module-customer/Model/Group/Resolver.php @@ -0,0 +1,40 @@ +resolverResource = $resolverResource; + } + + /** + * Return customer group id + * + * @param int $customerId + * @return int|null + */ + public function resolve(int $customerId) : ?int + { + return $this->resolverResource->resolve($customerId); + } +} diff -Nuar a/vendor/magento/module-customer/Model/ResourceModel/Group/Resolver.php b/vendor/magento/module-customer/Model/ResourceModel/Group/Resolver.php new file mode 100644 index 00000000000..82c2cf2449c --- /dev/null +++ b/vendor/magento/module-customer/Model/ResourceModel/Group/Resolver.php @@ -0,0 +1,58 @@ +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; + } +} diff -Nuar a/vendor/magento/module-customer-graph-ql/Model/Context/AddCustomerGroupToContext.php b/vendor/magento/module-customer-graph-ql/Model/Context/AddCustomerGroupToContext.php new file mode 100644 index 00000000000..d576475759a --- /dev/null +++ b/vendor/magento/module-customer-graph-ql/Model/Context/AddCustomerGroupToContext.php @@ -0,0 +1,53 @@ +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; + } +} diff -Nuar a/vendor/magento/module-customer-graph-ql/etc/extension_attributes.xml b/vendor/magento/module-customer-graph-ql/etc/extension_attributes.xml index 26840551eae..b8bdb5a46ca 100644 --- a/vendor/magento/module-customer-graph-ql/etc/extension_attributes.xml +++ b/vendor/magento/module-customer-graph-ql/etc/extension_attributes.xml @@ -8,5 +8,6 @@ + - \ No newline at end of file + diff -Nuar a/vendor/magento/module-customer-graph-ql/etc/graphql/di.xml b/vendor/magento/module-customer-graph-ql/etc/graphql/di.xml index 1ba0e457430..a4611291a37 100644 --- a/vendor/magento/module-customer-graph-ql/etc/graphql/di.xml +++ b/vendor/magento/module-customer-graph-ql/etc/graphql/di.xml @@ -17,6 +17,7 @@ Magento\CustomerGraphQl\Model\Context\AddUserInfoToContext + Magento\CustomerGraphQl\Model\Context\AddCustomerGroupToContext