34 $appConfig = $this->objectManager->get(Config::class);
42 foreach ($this->createdQuotes as
$quoteId) {
58 'operation' => self::SERVICE_NAME .
'CreateEmptyCart',
64 $this->assertGreaterThan(0,
$quoteId);
71 public function testCreateEmptyCartForCustomer()
74 $repository = $this->objectManager->create(\
Magento\Customer\Api\CustomerRepositoryInterface::class);
81 'resourcePath' =>
'/V1/customers/' .
$customerId .
'/carts',
87 'operation' => self::SERVICE_NAME .
'CreateEmptyCartForCustomer',
92 $this->assertGreaterThan(0,
$quoteId);
99 public function testCreateEmptyCartAndGetCartForCustomer()
105 $customerTokenService = $this->objectManager->create(
106 \
Magento\Integration\Api\CustomerTokenServiceInterface::class
112 'resourcePath' =>
'/V1/carts/mine',
119 $this->assertGreaterThan(0,
$quoteId);
124 'resourcePath' =>
'/V1/carts/mine',
139 public function testAssignCustomer()
142 $quote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)->load(
'test01',
'reserved_order_id');
145 $repository = $this->objectManager->create(\
Magento\Customer\Api\CustomerRepositoryInterface::class);
152 'resourcePath' =>
'/V1/carts/' .
$cartId,
157 'serviceVersion' =>
'V1',
158 'operation' => self::SERVICE_NAME .
'AssignCustomer',
168 $this->assertEmpty(
$quote->getCustomerId());
172 $quote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)->load(
'test01',
'reserved_order_id');
173 $this->assertEquals(0,
$quote->getCustomerIsGuest());
175 $this->assertEquals(
$customer->getFirstname(),
$quote->getCustomerFirstname());
176 $this->assertEquals(
$customer->getLastname(),
$quote->getCustomerLastname());
183 public function testAssignCustomerThrowsExceptionIfThereIsNoCustomerWithGivenId()
186 $quote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)->load(
'test01',
'reserved_order_id');
191 'serviceVersion' =>
'V1',
193 'operation' => self::SERVICE_NAME .
'AssignCustomer',
196 'resourcePath' =>
'/V1/carts/' .
$cartId,
220 'serviceVersion' =>
'V1',
221 'operation' => self::SERVICE_NAME .
'AssignCustomer',
224 'resourcePath' =>
'/V1/carts/' .
$cartId,
242 public function testAssignCustomerThrowsExceptionIfTargetCartIsNotAnonymous()
245 $customer = $this->objectManager->create(\
Magento\Customer\Model\Customer::class)->load(1);
248 $quote = $this->objectManager->create(\
Magento\
Quote\Model\Quote::class)->load(
'test01',
'reserved_order_id');
254 'resourcePath' =>
'/V1/carts/' .
$cartId,
258 'serviceVersion' =>
'V1',
259 'operation' => self::SERVICE_NAME .
'AssignCustomer',
277 public function testAssignCustomerThrowsExceptionIfCartIsAssignedToDifferentStore()
279 $repository = $this->objectManager->create(\
Magento\Customer\Api\CustomerRepositoryInterface::class);
283 $quote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)->load(
'test01',
'reserved_order_id');
291 'serviceVersion' =>
'V1',
292 'operation' => self::SERVICE_NAME .
'AssignCustomer',
296 'resourcePath' =>
'/V1/carts/' .
$cartId,
313 public function testAssignCustomerThrowsExceptionIfCustomerAlreadyHasActiveCart()
316 $customer = $this->objectManager->create(\
Magento\Customer\Model\Customer::class)->load(1);
319 $customerQuote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)
320 ->load(
'test_order_1',
'reserved_order_id');
321 $customerQuote->setIsActive(1)->save();
323 $quote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)->load(
'test01',
'reserved_order_id');
331 'operation' => self::SERVICE_NAME .
'AssignCustomer',
332 'serviceVersion' =>
'V1',
335 'resourcePath' =>
'/V1/carts/' .
$cartId,
347 $this->expectExceptionMessage(
348 "The customer can't be assigned to the cart because the customer already has an active cart." 355 public function testPlaceOrder()
358 $quote = $this->objectManager->create(\
Magento\Quote\Model\Quote::class)
359 ->load(
'test_order_1',
'reserved_order_id');
364 'service' =>
'quoteCartManagementV1',
365 'operation' =>
'quoteCartManagementV1PlaceOrder',
366 'serviceVersion' =>
'V1',
369 'resourcePath' =>
'/V1/carts/' .
$cartId .
'/order',
377 $order = $this->objectManager->create(\
Magento\Sales\Model\Order::class)->load($orderId);
379 $this->assertCount(1,
$items);
380 $this->assertEquals(
'Simple Product',
$items[0]->getName());
386 public function testPlaceOrderForMyCart()
392 $customerTokenService = $this->objectManager->create(
393 \
Magento\Integration\Api\CustomerTokenServiceInterface::class
399 'resourcePath' =>
'/V1/carts/mine/order',
408 $order = $this->objectManager->create(\
Magento\Sales\Model\Order::class)->load($orderId);
410 $this->assertCount(1,
$items);
411 $this->assertEquals(
'Simple Product',
$items[0]->getName());
419 public function testGetCartForCustomer()
423 $customerTokenService = $this->objectManager->create(
424 \
Magento\Integration\Api\CustomerTokenServiceInterface::class
428 $cart = $this->getCart(
'test01');
433 'resourcePath' =>
'/V1/carts/mine',
438 'service' =>
'quoteCartManagementV1',
439 'serviceVersion' =>
'V1',
440 'operation' =>
'quoteCartManagementV1GetCartForCustomer',
448 $this->assertEquals(
$cart->getId(), $cartData[
'id']);
449 $this->assertEquals(
$cart->getCreatedAt(), $cartData[
'created_at']);
450 $this->assertEquals(
$cart->getUpdatedAt(), $cartData[
'updated_at']);
451 $this->assertEquals(
$cart->getIsActive(), $cartData[
'is_active']);
452 $this->assertEquals(
$cart->getIsVirtual(), $cartData[
'is_virtual']);
453 $this->assertEquals(
$cart->getOrigOrderId(), $cartData[
'orig_order_id']);
454 $this->assertEquals(
$cart->getItemsCount(), $cartData[
'items_count']);
455 $this->assertEquals(
$cart->getItemsQty(), $cartData[
'items_qty']);
457 $this->assertContains(
'customer', $cartData);
458 $this->assertEquals(
false, $cartData[
'customer_is_guest']);
459 $this->assertContains(
'currency', $cartData);
460 $this->assertEquals(
$cart->getGlobalCurrencyCode(), $cartData[
'currency'][
'global_currency_code']);
461 $this->assertEquals(
$cart->getBaseCurrencyCode(), $cartData[
'currency'][
'base_currency_code']);
462 $this->assertEquals(
$cart->getQuoteCurrencyCode(), $cartData[
'currency'][
'quote_currency_code']);
463 $this->assertEquals(
$cart->getStoreCurrencyCode(), $cartData[
'currency'][
'store_currency_code']);
464 $this->assertEquals(
$cart->getBaseToGlobalRate(), $cartData[
'currency'][
'base_to_global_rate']);
465 $this->assertEquals(
$cart->getBaseToQuoteRate(), $cartData[
'currency'][
'base_to_quote_rate']);
466 $this->assertEquals(
$cart->getStoreToBaseRate(), $cartData[
'currency'][
'store_to_base_rate']);
467 $this->assertEquals(
$cart->getStoreToQuoteRate(), $cartData[
'currency'][
'store_to_quote_rate']);
477 protected function getCart($reservedOrderId)
480 $cart = $this->objectManager->get(\
Magento\Quote\Model\Quote::class);
481 $cart->load($reservedOrderId,
'reserved_order_id');
482 if (!
$cart->getId()) {
483 throw new \InvalidArgumentException(
'There is no quote with provided reserved order ID.');
testCreateEmptyCartForGuest()
_markTestAsRestOnly($message=null)
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
const RESOURCE_PATH_CUSTOMER_TOKEN
testAssignCustomerThrowsExceptionIfThereIsNoCartWithGivenId()
static getObjectManager()