Skip to content

Commit 9ebaebb

Browse files
author
Michael Logvin
committed
Merge branch 'MAGETWO-34740' into MAGETWO-35629
2 parents 2a43ae4 + 611d824 commit 9ebaebb

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* sales_quote_delete_after
2828
*
2929
* @method Quote setStoreId(int $value)
30-
* @method Quote setIsVirtual(int $value)
3130
* @method int getIsMultiShipping()
3231
* @method Quote setIsMultiShipping(int $value)
3332
* @method float getStoreToBaseRate()
@@ -556,6 +555,14 @@ public function setIsActive($isActive)
556555
return $this->setData(self::KEY_IS_ACTIVE, $isActive);
557556
}
558557

558+
/**
559+
* {@inheritdoc}
560+
*/
561+
public function setIsVirtual($isVirtual)
562+
{
563+
return $this->setData(self::KEY_IS_VIRTUAL, $isVirtual);
564+
}
565+
559566
/**
560567
* {@inheritdoc}
561568
*/
@@ -772,6 +779,9 @@ public function beforeSave()
772779
$this->setCustomerId($this->_customer->getId());
773780
}
774781

782+
//mark quote if it has virtual products only
783+
$this->setIsVirtual($this->getIsVirtual());
784+
775785
parent::beforeSave();
776786
}
777787

app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Quote\Model\Quote\Address;
1212
use Magento\Store\Model\ScopeInterface;
13+
use Magento\Quote\Api\Data\CartInterface;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415

1516
/**
@@ -1040,4 +1041,94 @@ public function testAddItem()
10401041

10411042
$this->quote->addItem($item);
10421043
}
1044+
1045+
/**
1046+
* @param array $productTypes
1047+
* @param int $expected
1048+
* @dataProvider dataProviderForTestBeforeSaveIsVirtualQuote
1049+
*/
1050+
public function testBeforeSaveIsVirtualQuote(array $productTypes, $expected)
1051+
{
1052+
$storeId = 1;
1053+
$currencyMock = $this->getMockBuilder('Magento\Directory\Model\Currency')
1054+
->disableOriginalConstructor()
1055+
->getMock();
1056+
$currencyMock->expects($this->any())
1057+
->method('getCode')
1058+
->will($this->returnValue('test_code'));
1059+
$currencyMock->expects($this->any())
1060+
->method('getRate')
1061+
->will($this->returnValue('test_rate'));
1062+
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
1063+
->disableOriginalConstructor()
1064+
->getMock();
1065+
$storeMock->expects($this->once())
1066+
->method('getBaseCurrency')
1067+
->will($this->returnValue($currencyMock));
1068+
$storeMock->expects($this->once())
1069+
->method('getCurrentCurrency')
1070+
->will($this->returnValue($currencyMock));
1071+
1072+
$this->storeManagerMock->expects($this->any())
1073+
->method('getStore')
1074+
->with($storeId)
1075+
->will($this->returnValue($storeMock));
1076+
$this->quote->setStoreId($storeId);
1077+
1078+
$collectionMock = $this->getMock(
1079+
'Magento\Quote\Model\Resource\Quote\Item\Collection',
1080+
[],
1081+
[],
1082+
'',
1083+
false
1084+
);
1085+
$items = [];
1086+
foreach ($productTypes as $type) {
1087+
$productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);;
1088+
$productMock->expects($this->any())->method('getIsVirtual')->willReturn($type);
1089+
1090+
$itemMock = $this->getMock(
1091+
'Magento\Quote\Model\Quote\Item',
1092+
['isDeleted', 'getParentItemId', 'getProduct'],
1093+
[],
1094+
'',
1095+
false
1096+
);
1097+
$itemMock->expects($this->any())
1098+
->method('isDeleted')
1099+
->willReturn(false);
1100+
$itemMock->expects($this->any())
1101+
->method('getParentItemId')
1102+
->willReturn(false);
1103+
$itemMock->expects($this->any())
1104+
->method('getProduct')
1105+
->willReturn($productMock);
1106+
$items[] = $itemMock;
1107+
}
1108+
$iterator = new \ArrayIterator($items);
1109+
$collectionMock->expects($this->any())
1110+
->method('getIterator')
1111+
->will($this->returnValue($iterator));
1112+
$this->quoteItemCollectionFactoryMock->expects($this->once())
1113+
->method('create')
1114+
->will($this->returnValue($collectionMock));
1115+
1116+
$this->quote->beforeSave();
1117+
$this->assertEquals($expected, $this->quote->getDataByKey(CartInterface::KEY_IS_VIRTUAL));
1118+
}
1119+
1120+
1121+
/**
1122+
* @return array
1123+
*/
1124+
public function dataProviderForTestBeforeSaveIsVirtualQuote()
1125+
{
1126+
return [
1127+
[[true], 1],
1128+
[[true, true], 1],
1129+
[[false], 0],
1130+
[[true, false], 0],
1131+
[[false, false], 0]
1132+
];
1133+
}
10431134
}

0 commit comments

Comments
 (0)