Skip to content

Commit 8f15d60

Browse files
author
Cristian Partica
committed
MAGETWO-31324: Tax labels aren't displayed for Bundle options of "multiple select" & "drop-down" types
- fix for the optionTemplate "data." was not needed, config format for price-bundle.js
1 parent 38f9431 commit 8f15d60

File tree

2 files changed

+120
-6
lines changed

2 files changed

+120
-6
lines changed

app/code/Magento/Tax/Model/Observer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,17 @@ public function updateProductOptions(\Magento\Framework\Event\Observer $observer
310310
// prepare correct template for options render
311311
if ($this->_taxData->displayBothPrices()) {
312312
$options['optionTemplate'] = sprintf(
313-
'<%%= data.label %%>'
314-
. '<%% if (data.finalPrice.value) { %%>'
315-
. ' <%%= data.finalPrice.formatted %%> (%1$s <%%= data.basePrice.formatted %%>)'
313+
'<%%= label %%>'
314+
. '<%% if (finalPrice.value) { %%>'
315+
. ' <%%= finalPrice.formatted %%> (%1$s <%%= basePrice.formatted %%>)'
316316
. '<%% } %%>',
317317
__('Excl. tax:')
318318
);
319319
} elseif ($this->_taxData->priceIncludesTax() && $this->_taxData->displayPriceExcludingTax()) {
320320
$options['optionTemplate'] = sprintf(
321-
'<%%= data.label %%>'
322-
. '<%% if (data.basePrice.value) { %%>'
323-
. ' <%%= data.basePrice.formatted %%>'
321+
'<%%= label %%>'
322+
. '<%% if (basePrice.value) { %%>'
323+
. ' <%%= basePrice.formatted %%>'
324324
. '<%% } %%>'
325325
);
326326
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Test class for \Magento\Weee\Model\Observer
9+
*/
10+
namespace Magento\Tax\Test\Unit\Model;
11+
12+
use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
14+
class ObserverTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* Tests the methods that rely on the ScopeConfigInterface object to provide their return values
18+
* @param array $expected
19+
* @param bool $displayBothPrices
20+
* @param bool $priceIncludesTax
21+
* @param bool $displayPriceExcludingTax
22+
* @dataProvider dataProviderUpdateProductOptions
23+
*/
24+
public function testUpdateProductOptions($expected, $displayBothPrices, $priceIncludesTax, $displayPriceExcludingTax)
25+
{
26+
27+
$frameworkObject= new \Magento\Framework\Object();
28+
$frameworkObject->setAdditionalOptions([]);
29+
30+
$product=$this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
31+
32+
$registry=$this->getMock('Magento\Framework\Registry', [], [], '', false);
33+
$registry->expects($this->any())
34+
->method('registry')
35+
->with('current_product')
36+
->will($this->returnValue($product));
37+
38+
$taxData=$this->getMock('Magento\Tax\Helper\Data', [], [], '', false);
39+
$taxData->expects($this->any())
40+
->method('getCalculationAlgorithm')
41+
->will($this->returnValue('TOTAL_BASE_CALCULATION'));
42+
43+
$taxData->expects($this->any())
44+
->method('displayBothPrices')
45+
->will($this->returnValue($displayBothPrices));
46+
47+
$taxData->expects($this->any())
48+
->method('priceIncludesTax')
49+
->will($this->returnValue($priceIncludesTax));
50+
51+
$taxData->expects($this->any())
52+
->method('displayPriceExcludingTax')
53+
->will($this->returnValue($displayPriceExcludingTax));
54+
55+
$eventObject=$this->getMock('Magento\Framework\Event', ['getResponseObject'], [], '', false);
56+
$eventObject->expects($this->any())
57+
->method('getResponseObject')
58+
->will($this->returnValue($frameworkObject));
59+
60+
$observerObject=$this->getMock('Magento\Framework\Event\Observer', [], [], '', false);
61+
62+
$observerObject->expects($this->any())
63+
->method('getEvent')
64+
->will($this->returnValue($eventObject));
65+
66+
$objectManager = new ObjectManager($this);
67+
$taxObserverObject = $objectManager->getObject(
68+
'Magento\Tax\Model\Observer',
69+
[
70+
'taxData' => $taxData,
71+
'registry' => $registry,
72+
]
73+
);
74+
75+
$taxObserverObject->updateProductOptions($observerObject);
76+
77+
$this->assertEquals($expected, $frameworkObject->getAdditionalOptions());
78+
}
79+
80+
/**
81+
* @return array
82+
*/
83+
public function dataProviderUpdateProductOptions()
84+
{
85+
return [
86+
[
87+
'expected' => [
88+
'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION',
89+
'optionTemplate' => '<%= label %><% if (finalPrice.value) { %> <%= finalPrice.formatted %> (Excl. tax: <%= basePrice.formatted %>)<% } %>',
90+
],
91+
'displayBothPrices' => true,
92+
'priceIncludesTax' => false,
93+
'displayPriceExcludingTax' => false,
94+
],
95+
[
96+
'expected' => [
97+
'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION',
98+
'optionTemplate' => '<%= label %><% if (basePrice.value) { %> <%= basePrice.formatted %><% } %>',
99+
],
100+
'displayBothPrices' => false,
101+
'priceIncludesTax' => true,
102+
'displayPriceExcludingTax' => true,
103+
],
104+
[
105+
'expected' => [
106+
'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION',
107+
],
108+
'displayBothPrices' => false,
109+
'priceIncludesTax' => false,
110+
'displayPriceExcludingTax' => false,
111+
],
112+
];
113+
}
114+
}

0 commit comments

Comments
 (0)