Skip to content

Commit 457b0ea

Browse files
committed
improved solution and test coverage
1 parent 706d2ec commit 457b0ea

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-12
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ private function formatAndFilterTierPrices(
155155
array $tierPrices,
156156
string $currencyCode
157157
): array {
158-
$this->resetFormatAndFilterTierPrices();
158+
$this->formatAndFilterTierPrices = [];
159+
$this->tierPricesQty = [];
159160
foreach ($tierPrices as $key => $tierPrice) {
160161
$tierPrice->setValue($this->priceCurrency->convertAndRound($tierPrice->getValue()));
161162
$this->formatTierPrices($productPrice, $currencyCode, $tierPrice);
@@ -215,14 +216,4 @@ private function filterTierPrices(
215216
$this->tierPricesQty[$qty] = $key;
216217
}
217218
}
218-
219-
/**
220-
* Remove all element from formatAndFilterTierPrices
221-
*/
222-
private function resetFormatAndFilterTierPrices()
223-
{
224-
foreach ($this->formatAndFilterTierPrices as $key => $value) {
225-
unset($this->formatAndFilterTierPrices[$key]);
226-
}
227-
}
228219
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function testGetLowestPriceForGuest()
118118
}
119119

120120
/**
121+
* @magentoApiDataFixture Magento/Catalog/_files/simple_product_without_tier_price.php
121122
* @magentoApiDataFixture Magento/Catalog/_files/three_simple_products_with_tier_price.php
122123
*/
123124
public function testGetCorrectDisplaingTierPriceForProducts()
@@ -140,9 +141,10 @@ public function testGetCorrectDisplaingTierPriceForProducts()
140141
}
141142
QUERY;
142143
$response = $this->graphQlQuery($query);
143-
$this->assertCount(1, $response['products']['items'][0]['price_tiers']);
144+
$this->assertCount(0, $response['products']['items'][0]['price_tiers']);
144145
$this->assertCount(1, $response['products']['items'][1]['price_tiers']);
145146
$this->assertCount(1, $response['products']['items'][2]['price_tiers']);
147+
$this->assertCount(1, $response['products']['items'][3]['price_tiers']);
146148
}
147149

148150
/**
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Store\Api\Data\WebsiteInterface;
14+
use Magento\Store\Api\WebsiteRepositoryInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
19+
/** @var WebsiteInterface $adminWebsite */
20+
$adminWebsite = $objectManager->get(WebsiteRepositoryInterface::class)->get('admin');
21+
22+
/** @var ProductRepositoryInterface $productRepository */
23+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
24+
/** @var $product Product */
25+
$product = $objectManager->create(Product::class);
26+
$product->setTypeId(Type::TYPE_SIMPLE)
27+
->setAttributeSetId($product->getDefaultAttributeSetId())
28+
->setWebsiteIds([1])
29+
->setName('Simple Product ' . 10)
30+
->setSku('simple_10')
31+
->setPrice(22)
32+
->setWeight(1)
33+
->setVisibility(Visibility::VISIBILITY_BOTH)
34+
->setStatus(Status::STATUS_ENABLED)
35+
->setStockData(
36+
[
37+
'use_config_manage_stock' => 1,
38+
'qty' => 100,
39+
'is_qty_decimal' => 0,
40+
'is_in_stock' => 1,
41+
]
42+
);
43+
44+
$productRepository->save($product);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
Bootstrap::getInstance()->getInstance()->reinitialize();
14+
15+
/** @var Registry $registry */
16+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
17+
18+
$registry->unregister('isSecureArea');
19+
$registry->register('isSecureArea', true);
20+
21+
/** @var ProductRepositoryInterface $productRepository */
22+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
23+
try {
24+
$product = $productRepository->get('simple_10', false, null, true);
25+
$productRepository->delete($product);
26+
} catch (NoSuchEntityException $e) {
27+
}
28+
$registry->unregister('isSecureArea');
29+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)