Skip to content

Commit b712f09

Browse files
author
Yu Tang
committed
Merge remote-tracking branch 'origin/FearlessKiwis-MAGETWO-44615-Add-product-to-guest-cart-via-API-shows-zero-price' into FearlessKiwis-develop-no-refactoring
2 parents 63222cf + 2c1d02b commit b712f09

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Sales\Api\Data\OrderInterfaceFactory as OrderFactory;
2121
use Magento\Sales\Api\OrderManagementInterface as OrderManagement;
2222
use Magento\Store\Model\StoreManagerInterface;
23+
use Magento\Quote\Model\Quote\Address;
2324

2425
/**
2526
* Class QuoteManagement
@@ -94,6 +95,11 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
9495
*/
9596
protected $customerModelFactory;
9697

98+
/**
99+
* @var \Magento\Quote\Model\Quote\AddressFactory
100+
*/
101+
protected $quoteAddressFactory;
102+
97103
/**
98104
* @var \Magento\Framework\Api\DataObjectHelper
99105
*/
@@ -138,6 +144,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
138144
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
139145
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
140146
* @param \Magento\Customer\Model\CustomerFactory $customerModelFactory
147+
* @param \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory,
141148
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
142149
* @param StoreManagerInterface $storeManager
143150
* @param \Magento\Checkout\Model\Session $checkoutSession
@@ -160,6 +167,7 @@ public function __construct(
160167
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
161168
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
162169
\Magento\Customer\Model\CustomerFactory $customerModelFactory,
170+
\Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory,
163171
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
164172
StoreManagerInterface $storeManager,
165173
\Magento\Checkout\Model\Session $checkoutSession,
@@ -180,6 +188,7 @@ public function __construct(
180188
$this->quoteRepository = $quoteRepository;
181189
$this->customerRepository = $customerRepository;
182190
$this->customerModelFactory = $customerModelFactory;
191+
$this->quoteAddressFactory = $quoteAddressFactory;
183192
$this->dataObjectHelper = $dataObjectHelper;
184193
$this->storeManager = $storeManager;
185194
$this->checkoutSession = $checkoutSession;
@@ -196,6 +205,9 @@ public function createEmptyCart()
196205
$storeId = $this->storeManager->getStore()->getStoreId();
197206
$quote = $this->createAnonymousCart($storeId);
198207

208+
$quote->setBillingAddress($this->quoteAddressFactory->create());
209+
$quote->setShippingAddress($this->quoteAddressFactory->create());
210+
199211
try {
200212
$this->quoteRepository->save($quote);
201213
} catch (\Exception $e) {

app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public function testCreateEmptyCart()
9898
{
9999
$maskedCartId = 'masked1cart2id3';
100100
$cartId = 1;
101-
102101
$this->quoteIdMaskMock->expects($this->once())->method('setQuoteId')->with($cartId)->willReturnSelf();
103102
$this->quoteIdMaskMock->expects($this->once())->method('save')->willReturnSelf();
104103
$this->quoteIdMaskMock->expects($this->once())->method('getMaskedId')->willreturn($maskedCartId);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
8686
*/
8787
protected $customerFactoryMock;
8888

89+
/**
90+
* @var \PHPUnit_Framework_MockObject_MockObject
91+
*/
92+
protected $quoteAddressFactory;
93+
8994
/**
9095
* @var \PHPUnit_Framework_MockObject_MockObject
9196
*/
@@ -207,6 +212,14 @@ protected function setUp()
207212
false
208213
);
209214

215+
$this->quoteAddressFactory = $this->getMock(
216+
'Magento\Quote\Model\Quote\AddressFactory',
217+
['create'],
218+
[],
219+
'',
220+
false
221+
);
222+
210223
$this->dataObjectHelperMock = $this->getMock('\Magento\Framework\Api\DataObjectHelper', [], [], '', false);
211224
$this->checkoutSessionMock = $this->getMock(
212225
'Magento\Checkout\Model\Session',
@@ -242,6 +255,7 @@ protected function setUp()
242255
'quoteRepository' => $this->quoteRepositoryMock,
243256
'customerRepository' => $this->customerRepositoryMock,
244257
'customerModelFactory' => $this->customerFactoryMock,
258+
'quoteAddressFactory' => $this->quoteAddressFactory,
245259
'dataObjectHelper' => $this->dataObjectHelperMock,
246260
'storeManager' => $this->storeManagerMock,
247261
'checkoutSession' => $this->checkoutSessionMock,
@@ -259,6 +273,13 @@ public function testCreateEmptyCartAnonymous()
259273

260274
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
261275

276+
$quoteAddress = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
277+
278+
$quoteMock->expects($this->any())->method('setBillingAddress')->with($quoteAddress)->willReturnSelf();
279+
$quoteMock->expects($this->any())->method('setShippingAddress')->with($quoteAddress)->willReturnSelf();
280+
281+
$this->quoteAddressFactory->expects($this->any())->method('create')->willReturn($quoteAddress);
282+
262283
$this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($quoteMock);
263284
$quoteMock->expects($this->any())->method('setStoreId')->with($storeId);
264285

@@ -688,6 +709,7 @@ public function testPlaceOrderIfCustomerIsGuest()
688709
'quoteRepository' => $this->quoteRepositoryMock,
689710
'customerRepository' => $this->customerRepositoryMock,
690711
'customerModelFactory' => $this->customerFactoryMock,
712+
'quoteAddressFactory' => $this->quoteAddressFactory,
691713
'dataObjectHelper' => $this->dataObjectHelperMock,
692714
'storeManager' => $this->storeManagerMock,
693715
'checkoutSession' => $this->checkoutSessionMock,
@@ -745,6 +767,7 @@ public function testPlaceOrder()
745767
'quoteRepository' => $this->quoteRepositoryMock,
746768
'customerRepository' => $this->customerRepositoryMock,
747769
'customerModelFactory' => $this->customerFactoryMock,
770+
'quoteAddressFactory' => $this->quoteAddressFactory,
748771
'dataObjectHelper' => $this->dataObjectHelperMock,
749772
'storeManager' => $this->storeManagerMock,
750773
'checkoutSession' => $this->checkoutSessionMock,

0 commit comments

Comments
 (0)