Skip to content

Commit 417d736

Browse files
author
Cari Spruiell
committed
MAGETWO-36273: Create /mine API for ShippingAddressManagement
- add /mine endpoints to webapi.xml - create corresponding api-functional test
1 parent ffc46d3 commit 417d736

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,26 @@
348348
</resources>
349349
</route>
350350

351+
<!-- Managing My Cart Shipping address -->
352+
<route url="/V1/carts/mine/shipping-address" method="GET">
353+
<service class="Magento\Quote\Api\ShippingAddressManagementInterface" method="get"/>
354+
<resources>
355+
<resource ref="self" />
356+
</resources>
357+
<data>
358+
<parameter name="cartId" force="true">%cart_id%</parameter>
359+
</data>
360+
</route>
361+
<route url="/V1/carts/mine/shipping-address" method="POST">
362+
<service class="Magento\Quote\Api\ShippingAddressManagementInterface" method="assign"/>
363+
<resources>
364+
<resource ref="self" />
365+
</resources>
366+
<data>
367+
<parameter name="cartId" force="true">%cart_id%</parameter>
368+
</data>
369+
</route>
370+
351371
<!-- Managing Cart Order -->
352372
<route url="/V1/carts/:cartId/order" method="PUT">
353373
<service class="Magento\Quote\Api\CartManagementInterface" method="placeOrder"/>

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,60 @@ public function testSetAddressForVirtualQuote()
207207

208208
$this->_webApiCall($serviceInfo, $requestData);
209209
}
210+
211+
/**
212+
* Test getting shipping address based on the customer's authentication token.
213+
*
214+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
215+
*/
216+
public function testGetMyAddress()
217+
{
218+
// get customer ID token
219+
/** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
220+
$customerTokenService = $this->objectManager->create(
221+
'Magento\Integration\Service\V1\CustomerTokenServiceInterface'
222+
);
223+
$token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
224+
225+
/** @var \Magento\Quote\Model\Quote $quote */
226+
$quote = $this->objectManager->create('Magento\Quote\Model\Quote');
227+
$quote->load('test_order_1', 'reserved_order_id');
228+
229+
/** @var \Magento\Quote\Model\Quote\Address $address */
230+
$address = $quote->getShippingAddress();
231+
232+
$addressData = [
233+
AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(),
234+
AddressInterface::KEY_ID => (int)$address->getId(),
235+
AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(),
236+
AddressInterface::KEY_REGION => $address->getRegion(),
237+
AddressInterface::KEY_REGION_ID => $address->getRegionId(),
238+
AddressInterface::KEY_REGION_CODE => $address->getRegionCode(),
239+
AddressInterface::KEY_STREET => $address->getStreet(),
240+
AddressInterface::KEY_COMPANY => $address->getCompany(),
241+
AddressInterface::KEY_TELEPHONE => $address->getTelephone(),
242+
AddressInterface::KEY_POSTCODE => $address->getPostcode(),
243+
AddressInterface::KEY_CITY => $address->getCity(),
244+
AddressInterface::KEY_FIRSTNAME => $address->getFirstname(),
245+
AddressInterface::KEY_LASTNAME => $address->getLastname(),
246+
AddressInterface::KEY_EMAIL => $address->getEmail()
247+
];
248+
249+
$serviceInfo = [
250+
'rest' => [
251+
'resourcePath' => self::RESOURCE_PATH . 'mine/shipping-address',
252+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
253+
'token' => $token
254+
],
255+
'soap' => [
256+
'service' => self::SERVICE_NAME,
257+
'serviceVersion' => self::SERVICE_VERSION,
258+
'operation' => self::SERVICE_NAME . 'Get',
259+
'token' => $token
260+
],
261+
];
262+
263+
$requestData = ['cartId' => $quote->getId()];
264+
$this->assertEquals($addressData, $this->_webApiCall($serviceInfo, $requestData));
265+
}
210266
}

0 commit comments

Comments
 (0)