Skip to content

Commit 3991d65

Browse files
author
Tang, Yu(ytang1)
committed
Merge pull request #293 from magento-fearless-kiwis/develop
[FearlessKiwis] Bug fixes
2 parents d31d651 + 64ef009 commit 3991d65

File tree

5 files changed

+237
-12
lines changed

5 files changed

+237
-12
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/FinalPriceResolver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class FinalPriceResolver implements PriceResolverInterface
1616
*/
1717
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
1818
{
19-
return $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)
20-
->getAmount()->getBaseAmount();
19+
return $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getValue();
2120
}
2221
}

app/code/Magento/Sales/view/adminhtml/templates/order/create/totals/tax.phtml

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
// @codingStandardsIgnoreFile
88

9+
$taxAmount = $block->getTotal()->getValue();
910
?>
11+
<?php if (($taxAmount == 0 && $this->helper('Magento\Tax\Helper\Data')->displayZeroTax()) || ($taxAmount > 0)): ?>
1012
<?php global $taxIter; $taxIter++; ?>
1113
<?php if ($this->helper('Magento\Tax\Helper\Data')->displayFullSummary()): ?>
1214
<?php $isTop = 1; ?>
@@ -50,3 +52,5 @@
5052
</td>
5153
<td style="<?php /* @escapeNotVerified */ echo $block->getTotal()->getStyle() ?>" class="admin__total-amount"><?php /* @escapeNotVerified */ echo $block->formatPrice($block->getTotal()->getValue()) ?></td>
5254
</tr>
55+
<?php endif;?>
56+

app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ protected function getRatesData($rates)
7575
* @param \Magento\Quote\Model\Quote\Address\Total[] $addressTotals
7676
* @return \Magento\Quote\Api\Data\TotalSegmentInterface[]
7777
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
78+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7879
*/
7980
public function aroundProcess(
8081
\Magento\Quote\Model\Cart\TotalsConverter $subject,
@@ -94,7 +95,11 @@ public function aroundProcess(
9495

9596
$detailsId = 1;
9697
$finalData = [];
97-
foreach (unserialize($taxes['full_info']) as $info) {
98+
$fullInfo = $taxes['full_info'];
99+
if (is_string($fullInfo)) {
100+
$fullInfo = unserialize($fullInfo);
101+
}
102+
foreach ($fullInfo as $info) {
98103
if ((array_key_exists('hidden', $info) && $info['hidden'])
99104
|| ($info['amount'] == 0 && $this->taxConfig->displayCartZeroTax())
100105
) {

app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php

100644100755
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu
299299
$totals = [];
300300
$store = $quote->getStore();
301301
$applied = $total->getAppliedTaxes();
302+
if (is_string($applied)) {
303+
$applied = unserialize($applied);
304+
}
302305
$amount = $total->getTaxAmount();
303306
if ($amount == null) {
304307
$this->enhanceTotalData($quote, $total);
@@ -311,15 +314,13 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu
311314
$area = 'taxes';
312315
}
313316

314-
if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
315-
$totals[] = [
316-
'code' => $this->getCode(),
317-
'title' => __('Tax'),
318-
'full_info' => $applied ? $applied : [],
319-
'value' => $amount,
320-
'area' => $area,
321-
];
322-
}
317+
$totals[] = [
318+
'code' => $this->getCode(),
319+
'title' => __('Tax'),
320+
'full_info' => $applied ? $applied : [],
321+
'value' => $amount,
322+
'area' => $area,
323+
];
323324

324325
/**
325326
* Modify subtotal
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Tax\Test\Unit\Model\Quote;
8+
9+
use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
class GrandTotalDetailsPluginTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Quote\Api\Data\TotalSegmentExtensionFactory|\PHPUnit_Framework_MockObject_MockObject
15+
*/
16+
protected $totalSegmentExtensionFactoryMock;
17+
18+
/**
19+
* @var \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $detailsFactoryMock;
22+
23+
/**
24+
* @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $ratesFactoryMock;
27+
28+
/**
29+
* @var \Magento\Tax\Model\Config|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $taxConfigMock;
32+
33+
/**
34+
* @var \Magento\Quote\Model\Cart\TotalsConverter|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $subjectMock;
37+
38+
/**
39+
* @var \Closure|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $closureMock;
42+
43+
/**
44+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
45+
*/
46+
protected $objectManagerHelper;
47+
48+
/**
49+
* @var \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin
50+
*/
51+
protected $model;
52+
53+
public function setUp()
54+
{
55+
$this->subjectMock = $this->getMockBuilder('\Magento\Quote\Model\Cart\TotalsConverter')
56+
->disableOriginalConstructor()
57+
->getMock();
58+
59+
$this->totalSegmentExtensionFactoryMock = $this->getMockBuilder(
60+
'\Magento\Quote\Api\Data\TotalSegmentExtensionFactory'
61+
)->disableOriginalConstructor()
62+
->getMock();
63+
64+
$this->detailsFactoryMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
68+
$this->ratesFactoryMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory')
69+
->disableOriginalConstructor()
70+
->getMock();
71+
72+
$this->taxConfigMock = $this->getMockBuilder('\Magento\Tax\Model\Config')
73+
->disableOriginalConstructor()
74+
->getMock();
75+
76+
$this->objectManagerHelper = new ObjectManager($this);
77+
$this->model = $this->objectManagerHelper->getObject(
78+
'\Magento\Tax\Model\Quote\GrandTotalDetailsPlugin',
79+
[
80+
'totalSegmentExtensionFactory' => $this->totalSegmentExtensionFactoryMock,
81+
'ratesFactory' => $this->ratesFactoryMock,
82+
'detailsFactory' => $this->detailsFactoryMock,
83+
'taxConfig' => $this->taxConfigMock,
84+
]
85+
);
86+
}
87+
88+
protected function setupTaxTotal(array $data)
89+
{
90+
$taxTotalMock = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address\Total')
91+
->disableOriginalConstructor()
92+
->getMock();
93+
94+
$taxTotalMock->expects($this->any())
95+
->method('getData')
96+
->willReturn($data);
97+
98+
return $taxTotalMock;
99+
}
100+
101+
protected function setupTaxRateFactoryMock(array $taxRate)
102+
{
103+
$taxRateMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalRatesInterface')
104+
->getMock();
105+
106+
$this->ratesFactoryMock->expects($this->once())
107+
->method('create')
108+
->with([])
109+
->willReturn($taxRateMock);
110+
111+
$taxRateMock->expects($this->once())
112+
->method('setPercent')
113+
->with($taxRate['percent'])
114+
->willReturnSelf();
115+
$taxRateMock->expects($this->once())
116+
->method('setTitle')
117+
->with($taxRate['title'])
118+
->willReturnSelf();
119+
return $taxRateMock;
120+
}
121+
122+
protected function setupTaxDetails(array $taxDetails)
123+
{
124+
$taxDetailsMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalDetailsInterface')
125+
->getMock();
126+
127+
$this->detailsFactoryMock->expects($this->once())
128+
->method('create')
129+
->willReturn($taxDetailsMock);
130+
131+
$taxDetailsMock->expects($this->once())
132+
->method('setAmount')
133+
->with($taxDetails['amount'])
134+
->willReturnSelf();
135+
136+
$taxDetailsMock->expects($this->once())
137+
->method('setRates')
138+
->with($taxDetails['rates'])
139+
->willReturnSelf();
140+
141+
$taxDetailsMock->expects($this->once())
142+
->method('setGroupId')
143+
->with(1)
144+
->willReturnSelf();
145+
146+
return $taxDetailsMock;
147+
}
148+
149+
public function testAroundProcess()
150+
{
151+
$taxRate = [
152+
'percent' => 8.25,
153+
'title' => 'TX',
154+
];
155+
$taxAmount = 10;
156+
157+
158+
$taxRateMock = $this->setupTaxRateFactoryMock($taxRate);
159+
160+
$taxDetailsMock = $this->setupTaxDetails(
161+
[
162+
'amount' => $taxAmount,
163+
'rates' => [$taxRateMock],
164+
]
165+
);
166+
167+
$taxTotalData = [
168+
'full_info' => [
169+
[
170+
'amount' => $taxAmount,
171+
'rates' => [$taxRate],
172+
],
173+
],
174+
];
175+
$taxTotalMock = $this->setupTaxTotal($taxTotalData);
176+
$addressTotals = [
177+
'tax' => $taxTotalMock,
178+
];
179+
180+
$extensionAttributeMock = $this->getMockBuilder(
181+
'\Magento\Quote\Api\Data\TotalSegmentExtensionInterface'
182+
)->setMethods(
183+
[
184+
'setTaxGrandtotalDetails',
185+
186+
]
187+
)->getMockForAbstractClass();
188+
$extensionAttributeMock->expects($this->once())
189+
->method('setTaxGrandtotalDetails')
190+
->with([$taxDetailsMock])
191+
->willReturnSelf();
192+
193+
194+
$taxSegmentMock = $this->getMockBuilder('\Magento\Quote\Model\Cart\TotalSegment')
195+
->disableOriginalConstructor()
196+
->getMock();
197+
$taxSegmentMock->expects($this->once())
198+
->method('getExtensionAttributes')
199+
->willReturn($extensionAttributeMock);
200+
$taxSegmentMock->expects($this->once())
201+
->method('setExtensionAttributes')
202+
->with($extensionAttributeMock)
203+
->willReturnSelf();
204+
205+
$totalSegments = [
206+
'tax' => $taxSegmentMock,
207+
];
208+
209+
$this->closureMock = function () use ($totalSegments) {
210+
return $totalSegments;
211+
};
212+
213+
$result = $this->model->aroundProcess($this->subjectMock, $this->closureMock, $addressTotals);
214+
$this->assertEquals($totalSegments, $result);
215+
}
216+
}

0 commit comments

Comments
 (0)