Skip to content

Commit 4837e80

Browse files
committed
ACP2E-1456: display bundle options taking into account catalog tax configurations
1 parent ec527e1 commit 4837e80

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,36 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
4848
*/
4949
private $catalogHelper;
5050

51+
/**
52+
* @var \Magento\Tax\Helper\Data|mixed
53+
*/
54+
private $taxHelper;
55+
5156
/**
5257
* @param \Magento\Framework\App\Helper\Context $context
5358
* @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration
5459
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
5560
* @param \Magento\Framework\Escaper $escaper
5661
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
5762
* @param \Magento\Catalog\Helper\Data|null $catalogHelper
63+
* @param \Magento\Tax\Helper\Data|null $taxHelper
5864
*/
5965
public function __construct(
6066
\Magento\Framework\App\Helper\Context $context,
6167
\Magento\Catalog\Helper\Product\Configuration $productConfiguration,
6268
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
6369
\Magento\Framework\Escaper $escaper,
6470
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
65-
\Magento\Catalog\Helper\Data $catalogHelper = null
71+
\Magento\Catalog\Helper\Data $catalogHelper = null,
72+
\Magento\Tax\Helper\Data $taxHelper = null
6673
) {
6774
$this->productConfiguration = $productConfiguration;
6875
$this->pricingHelper = $pricingHelper;
6976
$this->escaper = $escaper;
7077
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
7178
->get(\Magento\Framework\Serialize\Serializer\Json::class);
7279
$this->catalogHelper = $catalogHelper ?? ObjectManager::getInstance()->get(\Magento\Catalog\Helper\Data::class);
80+
$this->taxHelper = $taxHelper ?? ObjectManager::getInstance()->get(\Magento\Tax\Helper\Data::class);
7381
parent::__construct($context);
7482
}
7583

@@ -104,16 +112,14 @@ public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Mod
104112
/** @var \Magento\Bundle\Model\Product\Price $price */
105113
$price = $product->getPriceModel();
106114

107-
$selectionPrice = $price->getSelectionFinalTotalPrice(
115+
return $price->getSelectionFinalTotalPrice(
108116
$product,
109117
$selectionProduct,
110118
$item->getQty(),
111119
$this->getSelectionQty($product, $selectionProduct->getSelectionId()),
112120
false,
113121
true
114122
);
115-
116-
return $this->catalogHelper->getTaxPrice($selectionProduct, $selectionPrice);
117123
}
118124

119125
/**
@@ -162,12 +168,25 @@ public function getBundleOptions(ItemInterface $item)
162168
foreach ($bundleSelections as $bundleSelection) {
163169
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
164170
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+
}
165179
$option['value'][] = $qty . ' x '
166180
. $this->escaper->escapeHtml($bundleSelection->getName())
167181
. ' '
168182
. $this->pricingHelper->currency(
169-
$this->getSelectionFinalPrice($item, $bundleSelection)
170-
);
183+
$selectionFinalPrice
184+
)
185+
. ' '
186+
. ($displayBothPrices ? __('Excl. tax:') . ' '
187+
. $this->pricingHelper->currency(
188+
$selectionFinalPriceExclTax
189+
) : '');
171190
$option['has_html'] = true;
172191
}
173192
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class ConfigurationTest extends TestCase
6262
*/
6363
private $catalogHelper;
6464

65+
/**
66+
* @var \Magento\Tax\Helper\Data|MockObject
67+
*/
68+
private $taxHelper;
69+
6570
/**
6671
* @inheritDoc
6772
*/
@@ -78,6 +83,7 @@ protected function setUp(): void
7883
->onlyMethods(['unserialize'])
7984
->getMockForAbstractClass();
8085
$this->catalogHelper = $this->createPartialMock(\Magento\Catalog\Helper\Data::class, ['getTaxPrice']);
86+
$this->taxHelper = $this->createPartialMock(\Magento\Tax\Helper\Data::class, ['displayBothPrices']);
8187

8288
$this->serializer->expects($this->any())
8389
->method('unserialize')
@@ -94,7 +100,8 @@ function ($value) {
94100
'productConfiguration' => $this->productConfiguration,
95101
'escaper' => $this->escaper,
96102
'serializer' => $this->serializer,
97-
'catalogHelper' => $this->catalogHelper
103+
'catalogHelper' => $this->catalogHelper,
104+
'taxHelper' => $this->taxHelper
98105
]
99106
);
100107
}
@@ -271,7 +278,11 @@ public function testGetOptions(): void
271278
->willReturn('name');
272279
$this->catalogHelper->expects($this->any())
273280
->method('getTaxPrice')
281+
->with($itemOption, 15)
274282
->willReturn(15);
283+
$this->taxHelper->expects($this->any())
284+
->method('displayBothPrices')
285+
->willReturn(false);
275286
$this->pricingHelper->expects($this->once())->method('currency')->with(15)
276287
->willReturn('<span class="price">$15.00</span>');
277288
$priceModel->expects($this->once())->method('getSelectionFinalTotalPrice')->willReturn(15);

0 commit comments

Comments
 (0)