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-catalog-rule-graph-ql/Plugin/Pricing/Price/UpdateCatalogRulePrice.php b/vendor/magento/module-catalog-rule-graph-ql/Plugin/Pricing/Price/UpdateCatalogRulePrice.php
new file mode 100644
index 00000000000..61b9f70c49f
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/Plugin/Pricing/Price/UpdateCatalogRulePrice.php
@@ -0,0 +1,68 @@
+dateTime = $dateTime;
+ $this->ruleResource = $ruleResource;
+ }
+
+ /**
+ * Returns catalog rule value for logged in customer group
+ *
+ * @param CatalogRulePrice $catalogRulePrice
+ * @param float|boolean $value
+ * @return float|boolean
+ */
+ public function afterGetValue(
+ CatalogRulePrice $catalogRulePrice,
+ $value
+ ) {
+ $product = $catalogRulePrice->getProduct();
+ if ($product && $product->getCustomerGroupId()) {
+ $store = $product->getStore();
+ $value = $this->ruleResource->getRulePrice(
+ $this->dateTime->scopeDate($store->getId()),
+ $store->getWebsiteId(),
+ $product->getCustomerGroupId(),
+ $product->getId()
+ );
+ $value = $value ? (float) $value : false;
+ }
+
+ return $value;
+ }
+}
diff -Nuar a/vendor/magento/module-catalog-rule-graph-ql/README.md b/vendor/magento/module-catalog-rule-graph-ql/README.md
new file mode 100644
index 00000000000..16a36aa3ca0
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/README.md
@@ -0,0 +1,3 @@
+# CatalogRuleGraphQl
+
+The *Magento_CatalogRuleGraphQl* module applies catalog rules to products for GraphQL requests.
diff -Nuar a/vendor/magento/module-catalog-rule-graph-ql/composer.json b/vendor/magento/module-catalog-rule-graph-ql/composer.json
new file mode 100644
index 00000000000..c82d9bb20dd
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/composer.json
@@ -0,0 +1,24 @@
+{
+ "name": "magento/module-catalog-rule-graph-ql",
+ "description": "N/A",
+ "type": "magento2-module",
+ "require": {
+ "php": "~7.3.0||~7.4.0",
+ "magento/framework": "*"
+ },
+ "suggest": {
+ "magento/module-catalog-rule": "*"
+ },
+ "license": [
+ "OSL-3.0",
+ "AFL-3.0"
+ ],
+ "autoload": {
+ "files": [
+ "registration.php"
+ ],
+ "psr-4": {
+ "Magento\\CatalogRuleGraphQl\\": ""
+ }
+ }
+}
diff -Nuar a/vendor/magento/module-catalog-rule-graph-ql/etc/graphql/di.xml b/vendor/magento/module-catalog-rule-graph-ql/etc/graphql/di.xml
new file mode 100644
index 00000000000..571783edece
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/etc/graphql/di.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
diff -Nuar a/vendor/magento/module-catalog-rule-graph-ql/etc/graphql/events.xml b/vendor/magento/module-catalog-rule-graph-ql/etc/graphql/events.xml
new file mode 100644
index 00000000000..0d0a1fef535
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/etc/graphql/events.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
diff -Nuar a/vendor/magento/module-catalog-rule-graph-ql/etc/module.xml b/vendor/magento/module-catalog-rule-graph-ql/etc/module.xml
new file mode 100644
index 00000000000..affc22f35a7
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/etc/module.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff -Nuar a/vendor/magento/module-catalog-rule-graph-ql/registration.php b/vendor/magento/module-catalog-rule-graph-ql/registration.php
new file mode 100644
index 00000000000..df4dcd1cb47
--- /dev/null
+++ b/vendor/magento/module-catalog-rule-graph-ql/registration.php
@@ -0,0 +1,9 @@
+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..aaa2b85636f
--- /dev/null
+++ b/vendor/magento/module-customer-graph-ql/Model/Context/AddCustomerGroupToContext.php
@@ -0,0 +1,52 @@
+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 cb4ab0b7b27..9d5def55caf 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
diff -Nuar a/vendor/magento/module-quote-graph-ql/Model/Resolver/CartPrices.php b/vendor/magento/module-quote-graph-ql/Model/Resolver/CartPrices.php
index 6a57a7662af..66cc9ed11ed 100644
--- a/vendor/magento/module-quote-graph-ql/Model/Resolver/CartPrices.php
+++ b/vendor/magento/module-quote-graph-ql/Model/Resolver/CartPrices.php
@@ -45,6 +45,12 @@ class CartPrices implements ResolverInterface
/** @var Quote $quote */
$quote = $value['model'];
+ /**
+ * To calculate a right discount value
+ * before calculate totals
+ * need to reset Cart Fixed Rules in the quote
+ */
+ $quote->setCartFixedRules([]);
$cartTotals = $this->totalsCollector->collectQuoteTotals($quote);
$currency = $quote->getQuoteCurrencyCode();
diff -Nuar a/vendor/magento/module-sales-rule/Model/Validator.php b/vendor/magento/module-sales-rule/Model/Validator.php
index dad35165051..1099fc7823a 100644
--- a/vendor/magento/module-sales-rule/Model/Validator.php
+++ b/vendor/magento/module-sales-rule/Model/Validator.php
@@ -292,7 +292,7 @@ class Validator extends \Magento\Framework\Model\AbstractModel
public function processShippingAmount(Address $address)
{
$shippingAmount = $address->getShippingAmountForDiscount();
- if ($shippingAmount !== null) {
+ if (!empty($shippingAmount)) {
$baseShippingAmount = $address->getBaseShippingAmountForDiscount();
} else {
$shippingAmount = $address->getShippingAmount();