Skip to content

Commit 145959e

Browse files
author
Robert He
committed
Merge branch 'FearlessKiwis-MAGETWO-31324-Tax-labels-arent-displayed-for-Bundle-options-of-multiple-select-drop-down-types' of https://github.corp.ebay.com/magento-fearless-kiwis/magento2ce into develop
2 parents 9790c1d + 0c01a36 commit 145959e

File tree

3 files changed

+129
-7
lines changed

3 files changed

+129
-7
lines changed

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ define([
1717
qtyFieldSelector: 'input.qty',
1818
priceBoxSelector: '.price-box',
1919
optionHandlers: {},
20-
optionTemplate: '<%- label %>' +
21-
'<% if (finalPrice.value) { %>' +
22-
' +<%- finalPrice.formatted %>' +
20+
optionTemplate: '<%- data.label %>' +
21+
'<% if (data.finalPrice.value) { %>' +
22+
' +<%- data.finalPrice.formatted %>' +
2323
'<% } %>',
2424
controlContainer: 'dd', // should be eliminated
2525
priceFormat: {},
@@ -163,7 +163,9 @@ define([
163163
}
164164

165165
toTemplate = {
166-
label: optionConfig[optionValue] && optionConfig[optionValue].name
166+
data: {
167+
label: optionConfig[optionValue] && optionConfig[optionValue].name
168+
}
167169
};
168170
prices = optionConfig[optionValue].prices;
169171

@@ -172,7 +174,7 @@ define([
172174
value += _.reduce(price.adjustments, function (sum, x) {
173175
return sum + x;
174176
}, 0);
175-
toTemplate[type] = {
177+
toTemplate.data[type] = {
176178
value: value,
177179
formatted: utils.formatPrice(value, format)
178180
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ public function updateProductOptions(\Magento\Framework\Event\Observer $observer
312312
$options['optionTemplate'] = sprintf(
313313
'<%%= data.label %%>'
314314
. '<%% if (data.finalPrice.value) { %%>'
315-
. ' <%%= data.finalPrice.formatted %%> (%1$s <%%= data.basePrice.formatted %%>)'
315+
. ' +<%%= data.finalPrice.formatted %%> (%1$s <%%= data.basePrice.formatted %%>)'
316316
. '<%% } %%>',
317317
__('Excl. tax:')
318318
);
319319
} elseif ($this->_taxData->priceIncludesTax() && $this->_taxData->displayPriceExcludingTax()) {
320320
$options['optionTemplate'] = sprintf(
321321
'<%%= data.label %%>'
322322
. '<%% if (data.basePrice.value) { %%>'
323-
. ' <%%= data.basePrice.formatted %%>'
323+
. ' +<%%= data.basePrice.formatted %%>'
324324
. '<%% } %%>'
325325
);
326326
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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(
25+
$expected,
26+
$displayBothPrices,
27+
$priceIncludesTax,
28+
$displayPriceExcludingTax
29+
) {
30+
31+
$frameworkObject= new \Magento\Framework\Object();
32+
$frameworkObject->setAdditionalOptions([]);
33+
34+
$product=$this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
35+
36+
$registry=$this->getMock('Magento\Framework\Registry', [], [], '', false);
37+
$registry->expects($this->any())
38+
->method('registry')
39+
->with('current_product')
40+
->will($this->returnValue($product));
41+
42+
$taxData=$this->getMock('Magento\Tax\Helper\Data', [], [], '', false);
43+
$taxData->expects($this->any())
44+
->method('getCalculationAlgorithm')
45+
->will($this->returnValue('TOTAL_BASE_CALCULATION'));
46+
47+
$taxData->expects($this->any())
48+
->method('displayBothPrices')
49+
->will($this->returnValue($displayBothPrices));
50+
51+
$taxData->expects($this->any())
52+
->method('priceIncludesTax')
53+
->will($this->returnValue($priceIncludesTax));
54+
55+
$taxData->expects($this->any())
56+
->method('displayPriceExcludingTax')
57+
->will($this->returnValue($displayPriceExcludingTax));
58+
59+
$eventObject=$this->getMock('Magento\Framework\Event', ['getResponseObject'], [], '', false);
60+
$eventObject->expects($this->any())
61+
->method('getResponseObject')
62+
->will($this->returnValue($frameworkObject));
63+
64+
$observerObject=$this->getMock('Magento\Framework\Event\Observer', [], [], '', false);
65+
66+
$observerObject->expects($this->any())
67+
->method('getEvent')
68+
->will($this->returnValue($eventObject));
69+
70+
$objectManager = new ObjectManager($this);
71+
$taxObserverObject = $objectManager->getObject(
72+
'Magento\Tax\Model\Observer',
73+
[
74+
'taxData' => $taxData,
75+
'registry' => $registry,
76+
]
77+
);
78+
79+
$taxObserverObject->updateProductOptions($observerObject);
80+
81+
$this->assertEquals($expected, $frameworkObject->getAdditionalOptions());
82+
}
83+
84+
/**
85+
* @return array
86+
*/
87+
public function dataProviderUpdateProductOptions()
88+
{
89+
return [
90+
[
91+
'expected' => [
92+
'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION',
93+
'optionTemplate' => '<%= data.label %><% if (data.finalPrice.value) '.
94+
'{ %> +<%= data.finalPrice.formatted %> (Excl. tax: <%= data.basePrice.formatted %>)<% } %>',
95+
],
96+
'displayBothPrices' => true,
97+
'priceIncludesTax' => false,
98+
'displayPriceExcludingTax' => false,
99+
],
100+
[
101+
'expected' => [
102+
'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION',
103+
'optionTemplate' => '<%= data.label %><% if (data.basePrice.value) '.
104+
'{ %> +<%= data.basePrice.formatted %><% } %>',
105+
],
106+
'displayBothPrices' => false,
107+
'priceIncludesTax' => true,
108+
'displayPriceExcludingTax' => true,
109+
],
110+
[
111+
'expected' => [
112+
'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION',
113+
],
114+
'displayBothPrices' => false,
115+
'priceIncludesTax' => false,
116+
'displayPriceExcludingTax' => false,
117+
],
118+
];
119+
}
120+
}

0 commit comments

Comments
 (0)