Skip to content

Commit fc3de1b

Browse files
ENGCOM-8985: [32279][GraphQL] Fixed issue with tier price #32353
2 parents 67f0b71 + 8c322c9 commit fc3de1b

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Magento\Framework\GraphQl\Query\ResolverInterface;
2020
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
2121
use Magento\Framework\Pricing\PriceCurrencyInterface;
22-
use Magento\Store\Api\Data\StoreInterface;
2322

2423
/**
2524
* Resolver for price_tiers
@@ -125,6 +124,10 @@ public function resolve(
125124
return [];
126125
}
127126

127+
if (!$product->getTierPrices()) {
128+
return [];
129+
}
130+
128131
$productId = (int)$product->getId();
129132
$this->tiers->addProductFilter($productId);
130133

@@ -152,7 +155,8 @@ private function formatAndFilterTierPrices(
152155
array $tierPrices,
153156
string $currencyCode
154157
): array {
155-
158+
$this->formatAndFilterTierPrices = [];
159+
$this->tierPricesQty = [];
156160
foreach ($tierPrices as $key => $tierPrice) {
157161
$tierPrice->setValue($this->priceCurrency->convertAndRound($tierPrice->getValue()));
158162
$this->formatTierPrices($productPrice, $currencyCode, $tierPrice);

app/code/Magento/CatalogCustomerGraphQl/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"magento/framework": "*",
88
"magento/module-catalog": "*",
99
"magento/module-customer": "*",
10-
"magento/module-catalog-graph-ql": "*",
11-
"magento/module-store": "*"
10+
"magento/module-catalog-graph-ql": "*"
1211
},
1312
"license": [
1413
"OSL-3.0",

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCustomer/PriceTiersTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,41 @@ public function testGetLowestPriceForGuest()
117117
$this->assertEquals(round(7.25, 2), $this->getValueForQuantity(8, $itemTiers));
118118
}
119119

120+
/**
121+
* @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php
122+
* @magentoApiDataFixture Magento/Catalog/_files/three_simple_products_with_tier_price.php
123+
*/
124+
public function testProductTierPricesAreCorrectlyReturned()
125+
{
126+
$productSku = 'simple';
127+
$query = <<<QUERY
128+
{
129+
products(search: "{$productSku}") {
130+
items {
131+
sku
132+
name
133+
price_tiers {
134+
quantity
135+
final_price {
136+
value
137+
}
138+
}
139+
}
140+
}
141+
}
142+
QUERY;
143+
$response = $this->graphQlQuery($query);
144+
$productsWithTierPrices = ['simple_1','simple_2','simple_3'];
145+
146+
foreach ($response['products']['items'] as $key => $item) {
147+
if (in_array($item['sku'], $productsWithTierPrices)) {
148+
$this->assertCount(1, $response['products']['items'][$key]['price_tiers']);
149+
} else {
150+
$this->assertCount(0, $response['products']['items'][$key]['price_tiers']);
151+
}
152+
}
153+
}
154+
120155
/**
121156
* Get the tier price value for the given product quantity
122157
*

0 commit comments

Comments
 (0)