Skip to content

Commit e99a69b

Browse files
committed
ACP2E-1456: display bundle options taking into account cart tax configurations; fixed unit tests
1 parent 510bdd5 commit e99a69b

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundl
197197
$qty = $this->getSelectionQty($item->getProduct(), $bundleSelection->getSelectionId()) * 1;
198198
if ($qty) {
199199
$selectionPrice = $this->getSelectionFinalPrice($item, $bundleSelection);
200-
$selectionFinalPrice = $this->taxHelper->getTaxPrice($item->getProduct(), $selectionPrice);
201200

202201
$displayCartPricesBoth = $this->taxHelper->displayCartPricesBoth();
203202
if ($displayCartPricesBoth) {
@@ -207,6 +206,8 @@ private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundl
207206
$selectionFinalPriceExclTax =
208207
$this->taxHelper
209208
->getTaxPrice($product, $selectionPrice, false);
209+
} else {
210+
$selectionFinalPrice = $this->taxHelper->getTaxPrice($item->getProduct(), $selectionPrice);
210211
}
211212
$option['value'][] = $qty . ' x '
212213
. $this->escaper->escapeHtml($bundleSelection->getName())

app/code/Magento/Bundle/Pricing/Price/TaxPrice.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Bundle\Pricing\Price;
99

1010
use Magento\Catalog\Model\Product;
11+
use Magento\Checkout\Model\Session;
1112
use Magento\Customer\Api\GroupRepositoryInterface;
1213
use Magento\Customer\Model\Session as CustomerSession;
1314
use Magento\Framework\Exception\LocalizedException;
@@ -68,6 +69,11 @@ class TaxPrice
6869
*/
6970
private $customerGroupRepository;
7071

72+
/**
73+
* @var Session
74+
*/
75+
private $checkoutSession;
76+
7177
/**
7278
* @param StoreManagerInterface $storeManager
7379
* @param TaxClassKeyInterfaceFactory $taxClassKeyFactory
@@ -77,6 +83,7 @@ class TaxPrice
7783
* @param TaxCalculationInterface $taxCalculationService
7884
* @param CustomerSession $customerSession
7985
* @param GroupRepositoryInterface $customerGroupRepository
86+
* @param Session $checkoutSession
8087
*/
8188
public function __construct(
8289
StoreManagerInterface $storeManager,
@@ -86,7 +93,8 @@ public function __construct(
8693
QuoteDetailsItemInterfaceFactory $quoteDetailsItemFactory,
8794
TaxCalculationInterface $taxCalculationService,
8895
CustomerSession $customerSession,
89-
GroupRepositoryInterface $customerGroupRepository
96+
GroupRepositoryInterface $customerGroupRepository,
97+
Session $checkoutSession
9098
) {
9199
$this->storeManager = $storeManager;
92100
$this->taxClassKeyFactory = $taxClassKeyFactory;
@@ -96,6 +104,7 @@ public function __construct(
96104
$this->taxCalculationService = $taxCalculationService;
97105
$this->customerSession = $customerSession;
98106
$this->customerGroupRepository = $customerGroupRepository;
107+
$this->checkoutSession = $checkoutSession;
99108
}
100109

101110
/**
@@ -129,6 +138,7 @@ public function getTaxPrice(
129138
$customerTaxClassKey = $this->taxClassKeyFactory->create();
130139
$item = $this->quoteDetailsItemFactory->create();
131140
$quoteDetails = $this->quoteDetailsFactory->create();
141+
$customerQuote = $this->checkoutSession->getQuote();
132142

133143
if ($priceIncludesTax === null) {
134144
$priceIncludesTax = $this->taxConfig->priceIncludesTax($store);
@@ -154,6 +164,7 @@ public function getTaxPrice(
154164
->setUnitPrice($price);
155165

156166
$quoteDetails
167+
->setShippingAddress($customerQuote->getShippingAddress()->getDataModel())
157168
->setCustomerTaxClassKey($customerTaxClassKey)
158169
->setItems([$item])
159170
->setCustomerId($this->customerSession->getCustomerId());

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public function testGetBundleOptionsEmptyBundleSelectionIds(): void
227227
* @param $includingTax
228228
* @param $displayCartPriceBoth
229229
* @return void
230-
* @throws LocalizedException
231230
* @dataProvider getTaxConfiguration
232231
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
233232
*/
@@ -275,14 +274,21 @@ public function testGetOptions($includingTax, $displayCartPriceBoth): void
275274
->method('escapeHtml')
276275
->with('name')
277276
->willReturn('name');
278-
$this->taxHelper->expects($this->any())
279-
->method('getTaxPrice')
280-
->with($product, 15, $includingTax)
281-
->willReturn(15.00);
277+
if ($displayCartPriceBoth) {
278+
$this->taxHelper->expects($this->any())
279+
->method('getTaxPrice')
280+
->withConsecutive([$product, 15.00, !$includingTax], [$product, 15.00, $includingTax])
281+
->willReturnOnConsecutiveCalls(15.00, 15.00);
282+
} else {
283+
$this->taxHelper->expects($this->any())
284+
->method('getTaxPrice')
285+
->with($product, 15.00, $includingTax)
286+
->willReturn(15.00);
287+
}
282288
$this->taxHelper->expects($this->any())
283289
->method('displayCartPricesBoth')
284290
->willReturn((bool)$displayCartPriceBoth);
285-
$this->pricingHelper->expects($this->once())->method('currency')->with(15.00)
291+
$this->pricingHelper->expects($this->atLeastOnce())->method('currency')->with(15.00)
286292
->willReturn('<span class="price">$15.00</span>');
287293
$priceModel->expects($this->once())->method('getSelectionFinalTotalPrice')->willReturn(15.00);
288294
$selectionQty->expects($this->any())->method('getValue')->willReturn(1);
@@ -317,11 +323,16 @@ public function testGetOptions($includingTax, $displayCartPriceBoth): void
317323
$this->productConfiguration->expects($this->once())->method('getCustomOptions')->with($this->item)
318324
->willReturn([0 => ['label' => 'title', 'value' => 'value']]);
319325

326+
if ($displayCartPriceBoth) {
327+
$value = '1 x name <span class="price">$15.00</span> Excl. tax: <span class="price">$15.00</span>';
328+
} else {
329+
$value = '1 x name <span class="price">$15.00</span>';
330+
}
320331
$this->assertEquals(
321332
[
322333
[
323334
'label' => 'title',
324-
'value' => ['1 x name <span class="price">$15.00</span>'],
335+
'value' => [$value],
325336
'has_html' => true
326337
],
327338
['label' => 'title', 'value' => 'value']
@@ -338,10 +349,8 @@ public function testGetOptions($includingTax, $displayCartPriceBoth): void
338349
public function getTaxConfiguration(): array
339350
{
340351
return [
341-
[1, 0],
342-
[0, 0],
343-
[1, 1],
344-
[0, 1]
352+
[null, false],
353+
[false, true]
345354
];
346355
}
347356
}

0 commit comments

Comments
 (0)