Skip to content

Commit 6c285ad

Browse files
committed
moved part of the logic to separate method
1 parent 2d9740d commit 6c285ad

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

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

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,47 +120,62 @@ function () use ($productId, $context) {
120120

121121
$productPrice = $this->tiers->getProductRegularPrice($productId) ?? 0.0;
122122
$tierPrices = $this->tiers->getProductTierPrices($productId) ?? [];
123-
return $this->formatProductTierPrices($tierPrices, $productPrice, $store);
123+
return $this->filterAndFormatProductTierPrices($tierPrices, $productPrice, $store);
124124
}
125125
);
126126
}
127127

128128
/**
129-
* Format tier prices for output
129+
* Filter and format tier prices for output
130130
*
131131
* @param ProductTierPriceInterface[] $tierPrices
132132
* @param float $productPrice
133133
* @param StoreInterface $store
134134
* @return array
135135
*/
136-
private function formatProductTierPrices(array $tierPrices, float $productPrice, StoreInterface $store): array
137-
{
136+
private function filterAndFormatProductTierPrices(
137+
array $tierPrices,
138+
float $productPrice,
139+
StoreInterface $store
140+
): array {
138141
$tiers = [];
139142
$qtyCache = [];
140143

141144
foreach ($tierPrices as $key => $tierPrice) {
142-
$tierPrice->setValue($this->priceCurrency->convertAndRound($tierPrice->getValue()));
143-
$percentValue = $tierPrice->getExtensionAttributes()->getPercentageValue();
144-
if ($percentValue && is_numeric($percentValue)) {
145-
$discount = $this->discount->getDiscountByPercent($productPrice, (float)$percentValue);
146-
} else {
147-
$discount = $this->discount->getDiscountByDifference($productPrice, (float)$tierPrice->getValue());
148-
}
149-
150-
$tiers[] = [
151-
"discount" => $discount,
152-
"quantity" => $tierPrice->getQty(),
153-
"final_price" => [
154-
"value" => $tierPrice->getValue(),
155-
"currency" => $store->getCurrentCurrencyCode()
156-
]
157-
];
158-
145+
$this->formatProductTierPrices($productPrice, $store, $tierPrice, $tiers);
159146
$this->filterTierPrices($tierPrices, $key, $tierPrice, $qtyCache, $tiers);
160147
}
161148
return $tiers;
162149
}
163150

151+
/**
152+
* Format tier prices for output
153+
*
154+
* @param float $productPrice
155+
* @param StoreInterface $store
156+
* @param $tierPrice
157+
* @param $tiers
158+
*/
159+
private function formatProductTierPrices(float $productPrice, StoreInterface $store, &$tierPrice, &$tiers)
160+
{
161+
$tierPrice->setValue($this->priceCurrency->convertAndRound($tierPrice->getValue()));
162+
$percentValue = $tierPrice->getExtensionAttributes()->getPercentageValue();
163+
if ($percentValue && is_numeric($percentValue)) {
164+
$discount = $this->discount->getDiscountByPercent($productPrice, (float)$percentValue);
165+
} else {
166+
$discount = $this->discount->getDiscountByDifference($productPrice, (float)$tierPrice->getValue());
167+
}
168+
169+
$tiers[] = [
170+
"discount" => $discount,
171+
"quantity" => $tierPrice->getQty(),
172+
"final_price" => [
173+
"value" => $tierPrice->getValue(),
174+
"currency" => $store->getCurrentCurrencyCode()
175+
]
176+
];
177+
}
178+
164179
/**
165180
* Filter the lowest price for each quantity
166181
*

0 commit comments

Comments
 (0)