Skip to content

Commit

Permalink
Merge pull request #293 from magento-fearless-kiwis/develop
Browse files Browse the repository at this point in the history
[FearlessKiwis] Bug fixes
  • Loading branch information
Tang, Yu(ytang1) committed Jan 13, 2016
2 parents d31d651 + 64ef009 commit 3991d65
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class FinalPriceResolver implements PriceResolverInterface
*/
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
{
return $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)
->getAmount()->getBaseAmount();
return $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getValue();
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/Sales/view/adminhtml/templates/order/create/totals/tax.phtml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

// @codingStandardsIgnoreFile

$taxAmount = $block->getTotal()->getValue();
?>
<?php if (($taxAmount == 0 && $this->helper('Magento\Tax\Helper\Data')->displayZeroTax()) || ($taxAmount > 0)): ?>
<?php global $taxIter; $taxIter++; ?>
<?php if ($this->helper('Magento\Tax\Helper\Data')->displayFullSummary()): ?>
<?php $isTop = 1; ?>
Expand Down Expand Up @@ -50,3 +52,5 @@
</td>
<td style="<?php /* @escapeNotVerified */ echo $block->getTotal()->getStyle() ?>" class="admin__total-amount"><?php /* @escapeNotVerified */ echo $block->formatPrice($block->getTotal()->getValue()) ?></td>
</tr>
<?php endif;?>

7 changes: 6 additions & 1 deletion app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected function getRatesData($rates)
* @param \Magento\Quote\Model\Quote\Address\Total[] $addressTotals
* @return \Magento\Quote\Api\Data\TotalSegmentInterface[]
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function aroundProcess(
\Magento\Quote\Model\Cart\TotalsConverter $subject,
Expand All @@ -94,7 +95,11 @@ public function aroundProcess(

$detailsId = 1;
$finalData = [];
foreach (unserialize($taxes['full_info']) as $info) {
$fullInfo = $taxes['full_info'];
if (is_string($fullInfo)) {
$fullInfo = unserialize($fullInfo);
}
foreach ($fullInfo as $info) {
if ((array_key_exists('hidden', $info) && $info['hidden'])
|| ($info['amount'] == 0 && $this->taxConfig->displayCartZeroTax())
) {
Expand Down
19 changes: 10 additions & 9 deletions app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu
$totals = [];
$store = $quote->getStore();
$applied = $total->getAppliedTaxes();
if (is_string($applied)) {
$applied = unserialize($applied);
}
$amount = $total->getTaxAmount();
if ($amount == null) {
$this->enhanceTotalData($quote, $total);
Expand All @@ -311,15 +314,13 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu
$area = 'taxes';
}

if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
$totals[] = [
'code' => $this->getCode(),
'title' => __('Tax'),
'full_info' => $applied ? $applied : [],
'value' => $amount,
'area' => $area,
];
}
$totals[] = [
'code' => $this->getCode(),
'title' => __('Tax'),
'full_info' => $applied ? $applied : [],
'value' => $amount,
'area' => $area,
];

/**
* Modify subtotal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Tax\Test\Unit\Model\Quote;

use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class GrandTotalDetailsPluginTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Quote\Api\Data\TotalSegmentExtensionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $totalSegmentExtensionFactoryMock;

/**
* @var \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $detailsFactoryMock;

/**
* @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $ratesFactoryMock;

/**
* @var \Magento\Tax\Model\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $taxConfigMock;

/**
* @var \Magento\Quote\Model\Cart\TotalsConverter|\PHPUnit_Framework_MockObject_MockObject
*/
protected $subjectMock;

/**
* @var \Closure|\PHPUnit_Framework_MockObject_MockObject
*/
protected $closureMock;

/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManagerHelper;

/**
* @var \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin
*/
protected $model;

public function setUp()
{
$this->subjectMock = $this->getMockBuilder('\Magento\Quote\Model\Cart\TotalsConverter')
->disableOriginalConstructor()
->getMock();

$this->totalSegmentExtensionFactoryMock = $this->getMockBuilder(
'\Magento\Quote\Api\Data\TotalSegmentExtensionFactory'
)->disableOriginalConstructor()
->getMock();

$this->detailsFactoryMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory')
->disableOriginalConstructor()
->getMock();

$this->ratesFactoryMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory')
->disableOriginalConstructor()
->getMock();

$this->taxConfigMock = $this->getMockBuilder('\Magento\Tax\Model\Config')
->disableOriginalConstructor()
->getMock();

$this->objectManagerHelper = new ObjectManager($this);
$this->model = $this->objectManagerHelper->getObject(
'\Magento\Tax\Model\Quote\GrandTotalDetailsPlugin',
[
'totalSegmentExtensionFactory' => $this->totalSegmentExtensionFactoryMock,
'ratesFactory' => $this->ratesFactoryMock,
'detailsFactory' => $this->detailsFactoryMock,
'taxConfig' => $this->taxConfigMock,
]
);
}

protected function setupTaxTotal(array $data)
{
$taxTotalMock = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address\Total')
->disableOriginalConstructor()
->getMock();

$taxTotalMock->expects($this->any())
->method('getData')
->willReturn($data);

return $taxTotalMock;
}

protected function setupTaxRateFactoryMock(array $taxRate)
{
$taxRateMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalRatesInterface')
->getMock();

$this->ratesFactoryMock->expects($this->once())
->method('create')
->with([])
->willReturn($taxRateMock);

$taxRateMock->expects($this->once())
->method('setPercent')
->with($taxRate['percent'])
->willReturnSelf();
$taxRateMock->expects($this->once())
->method('setTitle')
->with($taxRate['title'])
->willReturnSelf();
return $taxRateMock;
}

protected function setupTaxDetails(array $taxDetails)
{
$taxDetailsMock = $this->getMockBuilder('\Magento\Tax\Api\Data\GrandTotalDetailsInterface')
->getMock();

$this->detailsFactoryMock->expects($this->once())
->method('create')
->willReturn($taxDetailsMock);

$taxDetailsMock->expects($this->once())
->method('setAmount')
->with($taxDetails['amount'])
->willReturnSelf();

$taxDetailsMock->expects($this->once())
->method('setRates')
->with($taxDetails['rates'])
->willReturnSelf();

$taxDetailsMock->expects($this->once())
->method('setGroupId')
->with(1)
->willReturnSelf();

return $taxDetailsMock;
}

public function testAroundProcess()
{
$taxRate = [
'percent' => 8.25,
'title' => 'TX',
];
$taxAmount = 10;


$taxRateMock = $this->setupTaxRateFactoryMock($taxRate);

$taxDetailsMock = $this->setupTaxDetails(
[
'amount' => $taxAmount,
'rates' => [$taxRateMock],
]
);

$taxTotalData = [
'full_info' => [
[
'amount' => $taxAmount,
'rates' => [$taxRate],
],
],
];
$taxTotalMock = $this->setupTaxTotal($taxTotalData);
$addressTotals = [
'tax' => $taxTotalMock,
];

$extensionAttributeMock = $this->getMockBuilder(
'\Magento\Quote\Api\Data\TotalSegmentExtensionInterface'
)->setMethods(
[
'setTaxGrandtotalDetails',

]
)->getMockForAbstractClass();
$extensionAttributeMock->expects($this->once())
->method('setTaxGrandtotalDetails')
->with([$taxDetailsMock])
->willReturnSelf();


$taxSegmentMock = $this->getMockBuilder('\Magento\Quote\Model\Cart\TotalSegment')
->disableOriginalConstructor()
->getMock();
$taxSegmentMock->expects($this->once())
->method('getExtensionAttributes')
->willReturn($extensionAttributeMock);
$taxSegmentMock->expects($this->once())
->method('setExtensionAttributes')
->with($extensionAttributeMock)
->willReturnSelf();

$totalSegments = [
'tax' => $taxSegmentMock,
];

$this->closureMock = function () use ($totalSegments) {
return $totalSegments;
};

$result = $this->model->aroundProcess($this->subjectMock, $this->closureMock, $addressTotals);
$this->assertEquals($totalSegments, $result);
}
}

0 comments on commit 3991d65

Please sign in to comment.