Skip to content

Commit

Permalink
ENGCOM-8985: [32279][GraphQL] Fixed issue with tier price #32353
Browse files Browse the repository at this point in the history
 - Merge Pull Request #32353 from Usik2203/magento2:32279-issue-with-tier-price
 - Merged commits:
   1. 3359cfa
   2. 706d2ec
   3. 457b0ea
   4. d5c4191
   5. 022d7bf
   6. 60e258f
   7. f494cb1
   8. 5590d7c
  • Loading branch information
magento-engcom-team committed Apr 23, 2021
2 parents 3f697e0 + 5590d7c commit 8c322c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
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

0 comments on commit 8c322c9

Please sign in to comment.