diff --git a/app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php b/app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php index efba88ff154bb..3c6cc849081ee 100644 --- a/app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php +++ b/app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php @@ -19,7 +19,6 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\Pricing\PriceCurrencyInterface; -use Magento\Store\Api\Data\StoreInterface; /** * Resolver for price_tiers @@ -125,6 +124,10 @@ public function resolve( return []; } + if (!$product->getTierPrices()) { + return []; + } + $productId = (int)$product->getId(); $this->tiers->addProductFilter($productId); @@ -152,7 +155,8 @@ private function formatAndFilterTierPrices( array $tierPrices, string $currencyCode ): array { - + $this->formatAndFilterTierPrices = []; + $this->tierPricesQty = []; foreach ($tierPrices as $key => $tierPrice) { $tierPrice->setValue($this->priceCurrency->convertAndRound($tierPrice->getValue())); $this->formatTierPrices($productPrice, $currencyCode, $tierPrice); diff --git a/app/code/Magento/CatalogCustomerGraphQl/composer.json b/app/code/Magento/CatalogCustomerGraphQl/composer.json index a7c887af0379b..ce80ee602327e 100644 --- a/app/code/Magento/CatalogCustomerGraphQl/composer.json +++ b/app/code/Magento/CatalogCustomerGraphQl/composer.json @@ -7,8 +7,7 @@ "magento/framework": "*", "magento/module-catalog": "*", "magento/module-customer": "*", - "magento/module-catalog-graph-ql": "*", - "magento/module-store": "*" + "magento/module-catalog-graph-ql": "*" }, "license": [ "OSL-3.0", diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCustomer/PriceTiersTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCustomer/PriceTiersTest.php index 767dcc5e0ab5c..071f9a6ea5121 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCustomer/PriceTiersTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCustomer/PriceTiersTest.php @@ -117,6 +117,41 @@ public function testGetLowestPriceForGuest() $this->assertEquals(round(7.25, 2), $this->getValueForQuantity(8, $itemTiers)); } + /** + * @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php + * @magentoApiDataFixture Magento/Catalog/_files/three_simple_products_with_tier_price.php + */ + public function testProductTierPricesAreCorrectlyReturned() + { + $productSku = 'simple'; + $query = <<graphQlQuery($query); + $productsWithTierPrices = ['simple_1','simple_2','simple_3']; + + foreach ($response['products']['items'] as $key => $item) { + if (in_array($item['sku'], $productsWithTierPrices)) { + $this->assertCount(1, $response['products']['items'][$key]['price_tiers']); + } else { + $this->assertCount(0, $response['products']['items'][$key]['price_tiers']); + } + } + } + /** * Get the tier price value for the given product quantity *