Skip to content

Commit 1c6a24b

Browse files
committed
MAGETWO-57610: [Backport] - User unable to do a full payment with gift card for the order containing gift wrap - for 2.0
1 parent 4ac2029 commit 1c6a24b

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

app/code/Magento/Quote/Model/Quote/Address/Total/Grand.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,52 @@
55
*/
66
namespace Magento\Quote\Model\Quote\Address\Total;
77

8+
/**
9+
* Class Grand
10+
*
11+
* @package Magento\Quote\Model\Quote\Address\Total
12+
*/
813
class Grand extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
914
{
1015
/**
1116
* Collect grand total address amount
1217
*
13-
* @param \Magento\Quote\Model\Quote $quote
18+
* @param \Magento\Quote\Model\Quote $quote
1419
* @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
15-
* @param \Magento\Quote\Model\Quote\Address\Total $total
20+
* @param \Magento\Quote\Model\Quote\Address\Total $total
21+
*
1622
* @return $this
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1724
*/
1825
public function collect(
1926
\Magento\Quote\Model\Quote $quote,
2027
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
2128
\Magento\Quote\Model\Quote\Address\Total $total
2229
) {
30+
$grandTotal = $total->getGrandTotal();
31+
$baseGrandTotal = $total->getBaseGrandTotal();
2332
$totals = array_sum($total->getAllTotalAmounts());
2433
$baseTotals = array_sum($total->getAllBaseTotalAmounts());
2534

26-
$total->setGrandTotal($totals);
27-
$total->setBaseGrandTotal($baseTotals);
35+
$total->setGrandTotal($grandTotal + $totals);
36+
$total->setBaseGrandTotal($baseGrandTotal + $baseTotals);
37+
2838
return $this;
2939
}
3040

3141
/**
3242
* Add grand total information to address
3343
*
34-
* @param \Magento\Quote\Model\Quote $quote
44+
* @param \Magento\Quote\Model\Quote $quote
3545
* @param \Magento\Quote\Model\Quote\Address\Total $total
36-
* @return $this
46+
*
47+
* @return array
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3749
*/
38-
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
39-
{
50+
public function fetch(
51+
\Magento\Quote\Model\Quote $quote,
52+
\Magento\Quote\Model\Quote\Address\Total $total
53+
) {
4054
return [
4155
'code' => $this->getCode(),
4256
'title' => __('Grand Total'),

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/GrandTest.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

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

10+
/**
11+
* Class GrandTest
12+
*
13+
* @package Magento\Quote\Test\Unit\Model\Quote\Address\Total
14+
*/
1015
class GrandTest extends \PHPUnit_Framework_TestCase
1116
{
1217
/**
@@ -17,9 +22,14 @@ class GrandTest extends \PHPUnit_Framework_TestCase
1722
protected function setUp()
1823
{
1924
$objectManager = new ObjectManager($this);
20-
$this->model = $objectManager->getObject('Magento\Quote\Model\Quote\Address\Total\Grand');
25+
$this->model = $objectManager->getObject(
26+
\Magento\Quote\Model\Quote\Address\Total\Grand::class
27+
);
2128
}
2229

30+
/**
31+
* Test case for quote totals collect
32+
*/
2333
public function testCollect()
2434
{
2535
$totals = [1, 2, 3.4];
@@ -28,20 +38,29 @@ public function testCollect()
2838
$grandTotalBase = 15.7; // 4 + 5 + 6.7
2939

3040
$totalMock = $this->getMock(
31-
'\Magento\Quote\Model\Quote\Address\Total',
32-
['getAllTotalAmounts', 'getAllBaseTotalAmounts', 'setGrandTotal', 'setBaseGrandTotal'],
41+
\Magento\Quote\Model\Quote\Address\Total::class,
42+
[
43+
'getAllTotalAmounts',
44+
'getAllBaseTotalAmounts',
45+
'setGrandTotal',
46+
'setBaseGrandTotal',
47+
'getGrandTotal',
48+
'getBaseGrandTotal'
49+
],
3350
[],
3451
'',
3552
false
3653
);
54+
$totalMock->expects($this->once())->method('getGrandTotal')->willReturn(2);
55+
$totalMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(2);
3756
$totalMock->expects($this->once())->method('getAllTotalAmounts')->willReturn($totals);
3857
$totalMock->expects($this->once())->method('getAllBaseTotalAmounts')->willReturn($totalsBase);
39-
$totalMock->expects($this->once())->method('setGrandTotal')->with($grandTotal);
40-
$totalMock->expects($this->once())->method('setBaseGrandTotal')->with($grandTotalBase);
58+
$totalMock->expects($this->once())->method('setGrandTotal')->with($grandTotal + 2);
59+
$totalMock->expects($this->once())->method('setBaseGrandTotal')->with($grandTotalBase + 2);
4160

4261
$this->model->collect(
43-
$this->getMock('\Magento\Quote\Model\Quote', [], [], '', false),
44-
$this->getMock('\Magento\Quote\Api\Data\ShippingAssignmentInterface'),
62+
$this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false),
63+
$this->getMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class),
4564
$totalMock
4665
);
4766
}

0 commit comments

Comments
 (0)