Skip to content

Commit d8528b2

Browse files
committed
ACP2E-1456: fix static and unit tests errors
1 parent 4837e80 commit d8528b2

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Bundle\Helper\Catalog\Product;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
89
use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface;
910
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
1011
use Magento\Framework\App\Helper\AbstractHelper;
@@ -130,7 +131,6 @@ public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Mod
130131
*
131132
* @param ItemInterface $item
132133
* @return array
133-
* phpcs:disable Generic.Metrics.NestingLevel
134134
*/
135135
public function getBundleOptions(ItemInterface $item)
136136
{
@@ -166,29 +166,7 @@ public function getBundleOptions(ItemInterface $item)
166166
$bundleSelections = $bundleOption->getSelections();
167167

168168
foreach ($bundleSelections as $bundleSelection) {
169-
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
170-
if ($qty) {
171-
$selectionPrice = $this->getSelectionFinalPrice($item, $bundleSelection);
172-
$selectionFinalPrice = $this->catalogHelper->getTaxPrice($item, $selectionPrice);
173-
174-
$displayBothPrices = $this->taxHelper->displayBothPrices();
175-
if ($displayBothPrices) {
176-
$selectionFinalPrice = $this->catalogHelper->getTaxPrice($item, $selectionPrice, true);
177-
$selectionFinalPriceExclTax = $this->catalogHelper->getTaxPrice($item, $selectionPrice, false);
178-
}
179-
$option['value'][] = $qty . ' x '
180-
. $this->escaper->escapeHtml($bundleSelection->getName())
181-
. ' '
182-
. $this->pricingHelper->currency(
183-
$selectionFinalPrice
184-
)
185-
. ' '
186-
. ($displayBothPrices ? __('Excl. tax:') . ' '
187-
. $this->pricingHelper->currency(
188-
$selectionFinalPriceExclTax
189-
) : '');
190-
$option['has_html'] = true;
191-
}
169+
$option = $this->getOptionPriceHtml($item, $bundleSelection, $option);
192170
}
193171

194172
if ($option['value']) {
@@ -201,7 +179,47 @@ public function getBundleOptions(ItemInterface $item)
201179

202180
return $options;
203181
}
204-
//phpcs:enable Generic.Metrics.NestingLevel
182+
183+
/**
184+
* Get bundle options' prices
185+
*
186+
* @param ItemInterface $item
187+
* @param ProductInterface $bundleSelection
188+
* @param array $option
189+
* @return array
190+
*/
191+
private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundleSelection, array $option): array
192+
{
193+
$product = $item->getProduct();
194+
$qty = $this->getSelectionQty($item->getProduct(), $bundleSelection->getSelectionId()) * 1;
195+
if ($qty) {
196+
$selectionPrice = $this->getSelectionFinalPrice($item, $bundleSelection);
197+
$selectionFinalPrice = $this->catalogHelper->getTaxPrice($item->getProduct(), $selectionPrice);
198+
199+
$displayBothPrices = $this->taxHelper->displayBothPrices();
200+
if ($displayBothPrices) {
201+
$selectionFinalPrice =
202+
$this->catalogHelper
203+
->getTaxPrice($product, $selectionPrice, true);
204+
$selectionFinalPriceExclTax =
205+
$this->catalogHelper
206+
->getTaxPrice($product, $selectionPrice, false);
207+
}
208+
$option['value'][] = $qty . ' x '
209+
. $this->escaper->escapeHtml($bundleSelection->getName())
210+
. ' '
211+
. $this->pricingHelper->currency(
212+
$selectionFinalPrice
213+
)
214+
. ' '
215+
. ($displayBothPrices ? __('Excl. tax:') . ' '
216+
. $this->pricingHelper->currency(
217+
$selectionFinalPriceExclTax
218+
) : '');
219+
$option['has_html'] = true;
220+
}
221+
return $option;
222+
}
205223

206224
/**
207225
* Retrieves product options list

app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ public function testGetSelectionFinalPrice(): void
163163
$price->expects($this->once())->method('getSelectionFinalTotalPrice')
164164
->with($product, $selectionProduct, $itemQty, 0, false, true);
165165

166-
$selectionPrice = $this->helper->getSelectionFinalPrice($this->item, $selectionProduct);
167-
$this->catalogHelper->getTaxPrice($selectionProduct, $selectionPrice);
166+
$this->helper->getSelectionFinalPrice($this->item, $selectionProduct);
168167
}
169168

170169
/**
@@ -278,7 +277,7 @@ public function testGetOptions(): void
278277
->willReturn('name');
279278
$this->catalogHelper->expects($this->any())
280279
->method('getTaxPrice')
281-
->with($itemOption, 15)
280+
->with($product, 15)
282281
->willReturn(15);
283282
$this->taxHelper->expects($this->any())
284283
->method('displayBothPrices')

0 commit comments

Comments
 (0)