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/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-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 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 93acf4e6993..6e71eef2f86 100644 --- a/vendor/magento/module-sales-rule/Model/Validator.php +++ b/vendor/magento/module-sales-rule/Model/Validator.php @@ -299,7 +299,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();