QuoteTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Quote\Model;
  8. use Magento\Catalog\Api\ProductRepositoryInterface;
  9. use Magento\Catalog\Model\ProductRepository;
  10. use Magento\Customer\Api\CustomerRepositoryInterface;
  11. use Magento\Customer\Api\Data\CustomerInterface;
  12. use Magento\Customer\Api\Data\CustomerInterfaceFactory;
  13. use Magento\Customer\Model\Data\Customer;
  14. use Magento\Framework\Exception\LocalizedException;
  15. use Magento\TestFramework\Helper\Bootstrap;
  16. use Magento\TestFramework\ObjectManager;
  17. use Magento\Framework\Api\SearchCriteriaBuilder;
  18. use Magento\Quote\Api\CartRepositoryInterface;
  19. use Magento\Framework\Api\ExtensibleDataInterface;
  20. /**
  21. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  22. */
  23. class QuoteTest extends \PHPUnit\Framework\TestCase
  24. {
  25. /**
  26. * @var ObjectManager
  27. */
  28. private $objectManager;
  29. /**
  30. * @inheritdoc
  31. */
  32. protected function setUp()
  33. {
  34. $this->objectManager = Bootstrap::getObjectManager();
  35. }
  36. /**
  37. * @param ExtensibleDataInterface $entity
  38. * @return array
  39. */
  40. private function convertToArray(ExtensibleDataInterface $entity): array
  41. {
  42. return $this->objectManager
  43. ->create(\Magento\Framework\Api\ExtensibleDataObjectConverter::class)
  44. ->toFlatArray($entity);
  45. }
  46. /**
  47. * @magentoDataFixture Magento/Catalog/_files/product_virtual.php
  48. * @magentoDataFixture Magento/Sales/_files/quote.php
  49. * @return void
  50. */
  51. public function testCollectTotalsWithVirtual(): void
  52. {
  53. $quote = $this->objectManager->create(Quote::class);
  54. $quote->load('test01', 'reserved_order_id');
  55. $productRepository = $this->objectManager->create(
  56. ProductRepositoryInterface::class
  57. );
  58. $product = $productRepository->get('virtual-product', false, null, true);
  59. $quote->addProduct($product);
  60. $quote->collectTotals();
  61. $this->assertEquals(2, $quote->getItemsQty());
  62. $this->assertEquals(1, $quote->getVirtualItemsQty());
  63. $this->assertEquals(20, $quote->getGrandTotal());
  64. $this->assertEquals(20, $quote->getBaseGrandTotal());
  65. }
  66. /**
  67. * @return void
  68. */
  69. public function testSetCustomerData(): void
  70. {
  71. /** @var Quote $quote */
  72. $quote = $this->objectManager->create(Quote::class);
  73. /** @var CustomerInterfaceFactory $customerFactory */
  74. $customerFactory = $this->objectManager->create(
  75. CustomerInterfaceFactory::class
  76. );
  77. /** @var \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */
  78. $dataObjectHelper = $this->objectManager->create(\Magento\Framework\Api\DataObjectHelper::class);
  79. $expected = $this->_getCustomerDataArray();
  80. $customer = $customerFactory->create();
  81. $dataObjectHelper->populateWithArray(
  82. $customer,
  83. $expected,
  84. \Magento\Customer\Api\Data\CustomerInterface::class
  85. );
  86. $this->assertEquals($expected, $this->convertToArray($customer));
  87. $quote->setCustomer($customer);
  88. $customer = $quote->getCustomer();
  89. $this->assertEquals($expected, $this->convertToArray($customer));
  90. $this->assertEquals('qa@example.com', $quote->getCustomerEmail());
  91. }
  92. /**
  93. * @return void
  94. */
  95. public function testUpdateCustomerData(): void
  96. {
  97. /** @var Quote $quote */
  98. $quote = $this->objectManager->create(Quote::class);
  99. $customerFactory = $this->objectManager->create(
  100. CustomerInterfaceFactory::class
  101. );
  102. /** @var \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */
  103. $dataObjectHelper = $this->objectManager->create(\Magento\Framework\Api\DataObjectHelper::class);
  104. $expected = $this->_getCustomerDataArray();
  105. //For save in repository
  106. $expected = $this->removeIdFromCustomerData($expected);
  107. $customerDataSet = $customerFactory->create();
  108. $dataObjectHelper->populateWithArray(
  109. $customerDataSet,
  110. $expected,
  111. \Magento\Customer\Api\Data\CustomerInterface::class
  112. );
  113. $this->assertEquals($expected, $this->convertToArray($customerDataSet));
  114. /**
  115. * @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
  116. */
  117. $customerRepository = $this->objectManager
  118. ->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
  119. $customerRepository->save($customerDataSet);
  120. $quote->setCustomer($customerDataSet);
  121. $expected = $this->_getCustomerDataArray();
  122. $expected = $this->changeEmailInCustomerData('test@example.com', $expected);
  123. $customerDataUpdated = $customerFactory->create();
  124. $dataObjectHelper->populateWithArray(
  125. $customerDataUpdated,
  126. $expected,
  127. \Magento\Customer\Api\Data\CustomerInterface::class
  128. );
  129. $quote->updateCustomerData($customerDataUpdated);
  130. $customer = $quote->getCustomer();
  131. $expected = $this->changeEmailInCustomerData('test@example.com', $expected);
  132. $actual = $this->convertToArray($customer);
  133. foreach ($expected as $item) {
  134. $this->assertContains($item, $actual);
  135. }
  136. $this->assertEquals('test@example.com', $quote->getCustomerEmail());
  137. }
  138. /**
  139. * Customer data is set to quote (which contains valid group ID).
  140. *
  141. * @return void
  142. */
  143. public function testGetCustomerGroupFromCustomer(): void
  144. {
  145. /** Preconditions */
  146. /** @var CustomerInterfaceFactory $customerFactory */
  147. $customerFactory = $this->objectManager->create(
  148. CustomerInterfaceFactory::class
  149. );
  150. $customerGroupId = 3;
  151. $customerData = $customerFactory->create()->setId(1)->setGroupId($customerGroupId);
  152. /** @var Quote $quote */
  153. $quote = $this->objectManager->create(Quote::class);
  154. $quote->setCustomer($customerData);
  155. $quote->unsetData('customer_group_id');
  156. /** Execute SUT */
  157. $this->assertEquals($customerGroupId, $quote->getCustomerGroupId(), "Customer group ID is invalid");
  158. }
  159. /**
  160. * @magentoDataFixture Magento/Customer/_files/customer_group.php
  161. * @return void
  162. */
  163. public function testGetCustomerTaxClassId(): void
  164. {
  165. /**
  166. * Preconditions: create quote and assign ID of customer group created in fixture to it.
  167. */
  168. $fixtureGroupCode = 'custom_group';
  169. $fixtureTaxClassId = 3;
  170. /** @var \Magento\Customer\Model\Group $group */
  171. $group = $this->objectManager->create(\Magento\Customer\Model\Group::class);
  172. $fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
  173. /** @var Quote $quote */
  174. $quote = $this->objectManager->create(Quote::class);
  175. $quote->setCustomerGroupId($fixtureGroupId);
  176. /** Execute SUT */
  177. $this->assertEquals($fixtureTaxClassId, $quote->getCustomerTaxClassId(), 'Customer tax class ID is invalid.');
  178. }
  179. /**
  180. * Billing and shipping address arguments are not passed, customer has default billing and shipping addresses.
  181. *
  182. * @magentoDataFixture Magento/Customer/_files/customer.php
  183. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  184. * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
  185. * @return void
  186. */
  187. public function testAssignCustomerWithAddressChangeAddressesNotSpecified(): void
  188. {
  189. /** Preconditions:
  190. * Customer with two addresses created
  191. * First address is default billing, second is default shipping.
  192. */
  193. /** @var Quote $quote */
  194. $quote = $this->objectManager->create(Quote::class);
  195. $customerData = $this->_prepareQuoteForTestAssignCustomerWithAddressChange($quote);
  196. /** Execute SUT */
  197. $quote->assignCustomerWithAddressChange($customerData);
  198. /** Check if SUT caused expected effects */
  199. $fixtureCustomerId = 1;
  200. $this->assertEquals($fixtureCustomerId, $quote->getCustomerId(), 'Customer ID in quote is invalid.');
  201. $expectedBillingAddressData = [
  202. 'street' => 'Green str, 67',
  203. 'telephone' => 3468676,
  204. 'postcode' => 75477,
  205. 'country_id' => 'US',
  206. 'city' => 'CityM',
  207. 'lastname' => 'Smith',
  208. 'firstname' => 'John',
  209. 'customer_id' => 1,
  210. 'customer_address_id' => 1,
  211. 'region_id' => 1
  212. ];
  213. $billingAddress = $quote->getBillingAddress();
  214. foreach ($expectedBillingAddressData as $field => $value) {
  215. $this->assertEquals(
  216. $value,
  217. $billingAddress->getData($field),
  218. "'{$field}' value in quote billing address is invalid."
  219. );
  220. }
  221. $expectedShippingAddressData = [
  222. 'customer_address_id' => 2,
  223. 'telephone' => 3234676,
  224. 'postcode' => 47676,
  225. 'country_id' => 'US',
  226. 'city' => 'CityX',
  227. 'street' => 'Black str, 48',
  228. 'lastname' => 'Smith',
  229. 'firstname' => 'John',
  230. 'customer_id' => 1,
  231. 'region_id' => 1
  232. ];
  233. $shippingAddress = $quote->getShippingAddress();
  234. foreach ($expectedShippingAddressData as $field => $value) {
  235. $this->assertEquals(
  236. $value,
  237. $shippingAddress->getData($field),
  238. "'{$field}' value in quote shipping address is invalid."
  239. );
  240. }
  241. }
  242. /**
  243. * Billing and shipping address arguments are passed, customer has default billing and shipping addresses.
  244. *
  245. * @magentoDataFixture Magento/Customer/_files/customer.php
  246. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  247. * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
  248. * @return void
  249. */
  250. public function testAssignCustomerWithAddressChange(): void
  251. {
  252. /** Preconditions:
  253. * Customer with two addresses created
  254. * First address is default billing, second is default shipping.
  255. */
  256. /** @var Quote $quote */
  257. $quote = $this->objectManager->create(Quote::class);
  258. $customerData = $this->_prepareQuoteForTestAssignCustomerWithAddressChange($quote);
  259. /** @var \Magento\Quote\Model\Quote\Address $quoteBillingAddress */
  260. $expectedBillingAddressData = [
  261. 'street' => 'Billing str, 67',
  262. 'telephone' => 16546757,
  263. 'postcode' => 2425457,
  264. 'country_id' => 'US',
  265. 'city' => 'CityBilling',
  266. 'lastname' => 'LastBilling',
  267. 'firstname' => 'FirstBilling',
  268. 'region_id' => 1
  269. ];
  270. $quoteBillingAddress = $this->objectManager->create(\Magento\Quote\Model\Quote\Address::class);
  271. $quoteBillingAddress->setData($expectedBillingAddressData);
  272. $expectedShippingAddressData = [
  273. 'telephone' => 787878787,
  274. 'postcode' => 117785,
  275. 'country_id' => 'US',
  276. 'city' => 'CityShipping',
  277. 'street' => 'Shipping str, 48',
  278. 'lastname' => 'LastShipping',
  279. 'firstname' => 'FirstShipping',
  280. 'region_id' => 1
  281. ];
  282. $quoteShippingAddress = $this->objectManager->create(\Magento\Quote\Model\Quote\Address::class);
  283. $quoteShippingAddress->setData($expectedShippingAddressData);
  284. /** Execute SUT */
  285. $quote->assignCustomerWithAddressChange($customerData, $quoteBillingAddress, $quoteShippingAddress);
  286. /** Check if SUT caused expected effects */
  287. $fixtureCustomerId = 1;
  288. $this->assertEquals($fixtureCustomerId, $quote->getCustomerId(), 'Customer ID in quote is invalid.');
  289. $billingAddress = $quote->getBillingAddress();
  290. foreach ($expectedBillingAddressData as $field => $value) {
  291. $this->assertEquals(
  292. $value,
  293. $billingAddress->getData($field),
  294. "'{$field}' value in quote billing address is invalid."
  295. );
  296. }
  297. $shippingAddress = $quote->getShippingAddress();
  298. foreach ($expectedShippingAddressData as $field => $value) {
  299. $this->assertEquals(
  300. $value,
  301. $shippingAddress->getData($field),
  302. "'{$field}' value in quote shipping address is invalid."
  303. );
  304. }
  305. }
  306. /**
  307. * @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
  308. * @return void
  309. */
  310. public function testAddProductUpdateItem(): void
  311. {
  312. /** @var Quote $quote */
  313. $quote = $this->objectManager->create(Quote::class);
  314. $quote->load('test01', 'reserved_order_id');
  315. $productStockQty = 100;
  316. $productRepository = $this->objectManager->create(
  317. ProductRepositoryInterface::class
  318. );
  319. $product = $productRepository->get('simple-1', false, null, true);
  320. $quote->addProduct($product, 50);
  321. $quote->setTotalsCollectedFlag(false)->collectTotals();
  322. $this->assertEquals(50, $quote->getItemsQty());
  323. $quote->addProduct($product, 50);
  324. $quote->setTotalsCollectedFlag(false)->collectTotals();
  325. $this->assertEquals(100, $quote->getItemsQty());
  326. $params = [
  327. 'related_product' => '',
  328. 'product' => $product->getId(),
  329. 'qty' => 1,
  330. 'id' => 0
  331. ];
  332. $updateParams = new \Magento\Framework\DataObject($params);
  333. $quote->updateItem($updateParams['id'], $updateParams);
  334. $quote->setTotalsCollectedFlag(false)->collectTotals();
  335. $this->assertEquals(1, $quote->getItemsQty());
  336. $this->expectException(\Magento\Framework\Exception\LocalizedException::class);
  337. // TODO: fix test or implementation as described in https://github.com/magento-engcom/msi/issues/1037
  338. // $this->expectExceptionMessage('The requested qty is not available');
  339. $updateParams['qty'] = $productStockQty + 1;
  340. $quote->updateItem($updateParams['id'], $updateParams);
  341. }
  342. /**
  343. * Prepare quote for testing assignCustomerWithAddressChange method.
  344. *
  345. * Customer with two addresses created. First address is default billing, second is default shipping.
  346. *
  347. * @param Quote $quote
  348. * @return CustomerInterface
  349. */
  350. protected function _prepareQuoteForTestAssignCustomerWithAddressChange(Quote $quote): CustomerInterface
  351. {
  352. $customerRepository = $this->objectManager->create(
  353. CustomerRepositoryInterface::class
  354. );
  355. $fixtureCustomerId = 1;
  356. /** @var \Magento\Customer\Model\Customer $customer */
  357. $customer = $this->objectManager->create(\Magento\Customer\Model\Customer::class);
  358. $fixtureSecondAddressId = 2;
  359. $customer->load($fixtureCustomerId)->setDefaultShipping($fixtureSecondAddressId)->save();
  360. $customerData = $customerRepository->getById($fixtureCustomerId);
  361. $this->assertEmpty(
  362. $quote->getBillingAddress()->getId(),
  363. "Precondition failed: billing address should be empty."
  364. );
  365. $this->assertEmpty(
  366. $quote->getShippingAddress()->getId(),
  367. "Precondition failed: shipping address should be empty."
  368. );
  369. return $customerData;
  370. }
  371. /**
  372. * @param string $email
  373. * @param array $customerData
  374. * @return array
  375. */
  376. protected function changeEmailInCustomerData(string $email, array $customerData): array
  377. {
  378. $customerData[\Magento\Customer\Model\Data\Customer::EMAIL] = $email;
  379. return $customerData;
  380. }
  381. /**
  382. * @param array $customerData
  383. * @return array
  384. */
  385. protected function removeIdFromCustomerData(array $customerData): array
  386. {
  387. unset($customerData[\Magento\Customer\Model\Data\Customer::ID]);
  388. return $customerData;
  389. }
  390. /**
  391. * @return array
  392. */
  393. protected function _getCustomerDataArray(): array
  394. {
  395. return [
  396. Customer::CONFIRMATION => 'test',
  397. Customer::CREATED_AT => '2/3/2014',
  398. Customer::CREATED_IN => 'Default',
  399. Customer::DEFAULT_BILLING => 'test',
  400. Customer::DEFAULT_SHIPPING => 'test',
  401. Customer::DOB => '2014-02-03 00:00:00',
  402. Customer::EMAIL => 'qa@example.com',
  403. Customer::FIRSTNAME => 'Joe',
  404. Customer::GENDER => 0,
  405. Customer::GROUP_ID => \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
  406. Customer::ID => 1,
  407. Customer::LASTNAME => 'Dou',
  408. Customer::MIDDLENAME => 'Ivan',
  409. Customer::PREFIX => 'Dr.',
  410. Customer::STORE_ID => 1,
  411. Customer::SUFFIX => 'Jr.',
  412. Customer::TAXVAT => 1,
  413. Customer::WEBSITE_ID => 1
  414. ];
  415. }
  416. /**
  417. * Test to verify that reserved_order_id will be changed if it already in used
  418. *
  419. * @magentoDataFixture Magento/Sales/_files/order.php
  420. * @magentoDataFixture Magento/Quote/_files/empty_quote.php
  421. * @return void
  422. */
  423. public function testReserveOrderId(): void
  424. {
  425. /** @var Quote $quote */
  426. $quote = $this->objectManager->create(Quote::class);
  427. $quote->load('reserved_order_id', 'reserved_order_id');
  428. $quote->reserveOrderId();
  429. $this->assertEquals('reserved_order_id', $quote->getReservedOrderId());
  430. $quote->setReservedOrderId('100000001');
  431. $quote->reserveOrderId();
  432. $this->assertNotEquals('100000001', $quote->getReservedOrderId());
  433. }
  434. /**
  435. * Test to verify that disabled product cannot be added to cart
  436. * @magentoDataFixture Magento/Quote/_files/is_not_salable_product.php
  437. * @return void
  438. */
  439. public function testAddedProductToQuoteIsSalable(): void
  440. {
  441. $productId = 99;
  442. /** @var ProductRepository $productRepository */
  443. $productRepository = $this->objectManager->get(ProductRepository::class);
  444. /** @var Quote $quote */
  445. $product = $productRepository->getById($productId, false, null, true);
  446. $this->expectException(LocalizedException::class);
  447. $this->expectExceptionMessage('Product that you are trying to add is not available.');
  448. $quote = $this->objectManager->create(Quote::class);
  449. $quote->addProduct($product);
  450. }
  451. /**
  452. * @magentoDataFixture Magento/Sales/_files/quote.php
  453. * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  454. * @return void
  455. */
  456. public function testGetItemById(): void
  457. {
  458. $quote = $this->objectManager->create(Quote::class);
  459. $quote->load('test01', 'reserved_order_id');
  460. $quoteItem = $this->objectManager->create(\Magento\Quote\Model\Quote\Item::class);
  461. $productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
  462. $product = $productRepository->get('simple');
  463. $quoteItem->setProduct($product);
  464. $quote->addItem($quoteItem);
  465. $quote->save();
  466. $this->assertInstanceOf(\Magento\Quote\Model\Quote\Item::class, $quote->getItemById($quoteItem->getId()));
  467. $this->assertEquals($quoteItem->getId(), $quote->getItemById($quoteItem->getId())->getId());
  468. }
  469. /**
  470. * Tests of quotes merging.
  471. *
  472. * @param int|null $guestItemGiftMessageId
  473. * @param int|null $customerItemGiftMessageId
  474. * @param int|null $guestOrderGiftMessageId
  475. * @param int|null $customerOrderGiftMessageId
  476. * @param int|null $expectedItemGiftMessageId
  477. * @param int|null $expectedOrderGiftMessageId
  478. *
  479. * @magentoDataFixture Magento/Sales/_files/quote.php
  480. * @dataProvider giftMessageDataProvider
  481. * @throws LocalizedException
  482. * @return void
  483. */
  484. public function testMerge(
  485. $guestItemGiftMessageId,
  486. $customerItemGiftMessageId,
  487. $guestOrderGiftMessageId,
  488. $customerOrderGiftMessageId,
  489. $expectedItemGiftMessageId,
  490. $expectedOrderGiftMessageId
  491. ): void {
  492. $productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
  493. $product = $productRepository->get('simple', false, null, true);
  494. /** @var Quote $quote */
  495. $guestQuote = $this->getQuote('test01');
  496. $guestQuote->setGiftMessageId($guestOrderGiftMessageId);
  497. /** @var Quote $customerQuote */
  498. $customerQuote = $this->objectManager->create(Quote::class);
  499. $customerQuote->setReservedOrderId('test02')
  500. ->setStoreId($guestQuote->getStoreId())
  501. ->addProduct($product);
  502. $customerQuote->setGiftMessageId($customerOrderGiftMessageId);
  503. $guestItem = $guestQuote->getItemByProduct($product);
  504. $guestItem->setGiftMessageId($guestItemGiftMessageId);
  505. $customerItem = $customerQuote->getItemByProduct($product);
  506. $customerItem->setGiftMessageId($customerItemGiftMessageId);
  507. $customerQuote->merge($guestQuote);
  508. $mergedItemItem = $customerQuote->getItemByProduct($product);
  509. self::assertEquals($expectedOrderGiftMessageId, $customerQuote->getGiftMessageId());
  510. self::assertEquals($expectedItemGiftMessageId, $mergedItemItem->getGiftMessageId());
  511. }
  512. /**
  513. * Provides order- and item-level gift message Id.
  514. *
  515. * @return array
  516. */
  517. public function giftMessageDataProvider(): array
  518. {
  519. return [
  520. [
  521. 'guestItemId' => null,
  522. 'customerItemId' => 1,
  523. 'guestOrderId' => null,
  524. 'customerOrderId' => 11,
  525. 'expectedItemId' => 1,
  526. 'expectedOrderId' => 11
  527. ],
  528. [
  529. 'guestItemId' => 1,
  530. 'customerItemId' => 2,
  531. 'guestOrderId' => 11,
  532. 'customerOrderId' => 22,
  533. 'expectedItemId' => 1,
  534. 'expectedOrderId' => 11
  535. ]
  536. ];
  537. }
  538. /**
  539. * Gets quote by reserved order id.
  540. *
  541. * @param string $reservedOrderId
  542. * @return Quote
  543. */
  544. private function getQuote(string $reservedOrderId): Quote
  545. {
  546. /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
  547. $searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
  548. $searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
  549. ->create();
  550. /** @var CartRepositoryInterface $quoteRepository */
  551. $quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
  552. $items = $quoteRepository->getList($searchCriteria)->getItems();
  553. return array_pop($items);
  554. }
  555. }