Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[32279][GraphQL] Fixed issue with tier price #32353

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +124,10 @@ public function resolve(
return [];
}

if (!$product->getTierPrices()) {
return [];
}

$productId = (int)$product->getId();
$this->tiers->addProductFilter($productId);

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/CatalogCustomerGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<QUERY
{
products(search: "{$productSku}") {
items {
sku
name
price_tiers {
quantity
final_price {
value
}
}
}
}
}
QUERY;
$response = $this->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
*
Expand Down