Skip to content

Commit 7f65d58

Browse files
committed
MAGETWO-36269: Create /mine APIs for CartManagement
- Added /mine endpoint for placeOrder - Added api-functional test case to cover this endpoint
1 parent c6d8407 commit 7f65d58

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

app/code/Magento/Quote/etc/webapi.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959
<parameter name="customerId" force="true">%customer_id%</parameter>
6060
</data>
6161
</route>
62+
<route url="/V1/carts/mine/order" method="PUT">
63+
<service class="Magento\Quote\Api\CartManagementInterface" method="placeOrder"/>
64+
<resources>
65+
<resource ref="self" />
66+
</resources>
67+
<data>
68+
<parameter name="cartId" force="true">%cart_id%</parameter>
69+
</data>
70+
</route>
6271

6372
<!-- Managing guest carts -->
6473

dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,41 @@ public function testPlaceOrder()
369369
$quote->delete();
370370
}
371371

372+
/**
373+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_check_payment.php
374+
*/
375+
public function testPlaceOrderForMyCart()
376+
{
377+
$this->_markTestAsRestOnly();
378+
379+
// get customer ID token
380+
/** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
381+
$customerTokenService = $this->objectManager->create(
382+
'Magento\Integration\Service\V1\CustomerTokenServiceInterface'
383+
);
384+
$token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
385+
386+
/** @var $quote \Magento\Quote\Model\Quote */
387+
$quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test_order_1', 'reserved_order_id');
388+
389+
$serviceInfo = [
390+
'rest' => [
391+
'resourcePath' => '/V1/carts/mine/order',
392+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
393+
'token' => $token
394+
],
395+
];
396+
397+
$orderId = $this->_webApiCall($serviceInfo, []);
398+
399+
/** @var \Magento\Sales\Model\Order $order */
400+
$order = $this->objectManager->create('Magento\Sales\Model\Order')->load($orderId);
401+
$items = $order->getAllItems();
402+
$this->assertCount(1, $items);
403+
$this->assertEquals('Simple Product', $items[0]->getName());
404+
$quote->delete();
405+
}
406+
372407
/**
373408
* Test to get my cart based on customer authentication token or session
374409
*

0 commit comments

Comments
 (0)