Skip to content

Commit f1bf163

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90135' into 2.3-develop-pr12
2 parents d1b52aa + b2a0777 commit f1bf163

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,10 @@ public function getCustomerCart()
714714
$this->_cart = $this->quoteFactory->create();
715715

716716
$customerId = (int)$this->getSession()->getCustomerId();
717+
$storeId = (int)$this->getSession()->getStoreId();
717718
if ($customerId) {
718719
try {
719-
$this->_cart = $this->quoteRepository->getForCustomer($customerId);
720+
$this->_cart = $this->quoteRepository->getForCustomer($customerId, [$storeId]);
720721
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
721722
$this->_cart->setStore($this->getSession()->getStore());
722723
$customerData = $this->customerRepository->getById($customerId);

app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
use Magento\Framework\Api\DataObjectHelper;
1919
use Magento\Framework\App\RequestInterface;
2020
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
21+
use Magento\Quote\Api\CartRepositoryInterface;
2122
use Magento\Quote\Model\Quote;
2223
use Magento\Quote\Model\Quote\Address;
2324
use Magento\Quote\Model\Quote\Item;
2425
use Magento\Quote\Model\Quote\Item\Updater;
2526
use Magento\Sales\Model\AdminOrder\Create;
2627
use Magento\Sales\Model\AdminOrder\Product;
28+
use Magento\Quote\Model\QuoteFactory;
2729
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2830

2931
/**
@@ -39,6 +41,16 @@ class CreateTest extends \PHPUnit\Framework\TestCase
3941
*/
4042
private $adminOrderCreate;
4143

44+
/**
45+
* @var CartRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $quoteRepository;
48+
49+
/**
50+
* @var QuoteFactory|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $quoteFactory;
53+
4254
/**
4355
* @var SessionQuote|MockObject
4456
*/
@@ -76,12 +88,22 @@ class CreateTest extends \PHPUnit\Framework\TestCase
7688

7789
protected function setUp()
7890
{
79-
$this->sessionQuote = $this->createMock(SessionQuote::class);
8091
$this->formFactory = $this->createPartialMock(FormFactory::class, ['create']);
92+
$this->quoteFactory = $this->createPartialMock(QuoteFactory::class, ['create']);
8193
$this->customerFactory = $this->createPartialMock(CustomerInterfaceFactory::class, ['create']);
8294

8395
$this->itemUpdater = $this->createMock(Updater::class);
8496

97+
$this->quoteRepository = $this->getMockBuilder(CartRepositoryInterface::class)
98+
->disableOriginalConstructor()
99+
->setMethods(['getForCustomer'])
100+
->getMockForAbstractClass();
101+
102+
$this->sessionQuote = $this->getMockBuilder(\Magento\Backend\Model\Session\Quote::class)
103+
->disableOriginalConstructor()
104+
->setMethods(['getQuote', 'getStoreId', 'getCustomerId'])
105+
->getMock();
106+
85107
$this->customerMapper = $this->getMockBuilder(Mapper::class)
86108
->setMethods(['toFlatArray'])
87109
->disableOriginalConstructor()
@@ -103,6 +125,8 @@ protected function setUp()
103125
'quoteItemUpdater' => $this->itemUpdater,
104126
'customerMapper' => $this->customerMapper,
105127
'dataObjectHelper' => $this->dataObjectHelper,
128+
'quoteRepository' => $this->quoteRepository,
129+
'quoteFactory' => $this->quoteFactory,
106130
]
107131
);
108132
}
@@ -264,4 +288,28 @@ public function testApplyCoupon()
264288
$object = $this->adminOrderCreate->applyCoupon($couponCode);
265289
self::assertEquals($this->adminOrderCreate, $object);
266290
}
291+
292+
public function testGetCustomerCart()
293+
{
294+
$storeId = 2;
295+
$customerId = 2;
296+
$cartResult = [
297+
'cart' => true,
298+
];
299+
300+
$this->quoteFactory->expects($this->once())
301+
->method('create');
302+
$this->sessionQuote->expects($this->once())
303+
->method('getStoreId')
304+
->willReturn($storeId);
305+
$this->sessionQuote->expects($this->once())
306+
->method('getCustomerId')
307+
->willReturn($customerId);
308+
$this->quoteRepository->expects($this->once())
309+
->method('getForCustomer')
310+
->with($customerId, [$storeId])
311+
->willReturn($cartResult);
312+
313+
$this->assertEquals($cartResult, $this->adminOrderCreate->getCustomerCart());
314+
}
267315
}

0 commit comments

Comments
 (0)