|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Quote\Api; |
| 7 | + |
| 8 | +use Magento\Framework\Api\ExtensibleDataInterface; |
| 9 | +use Magento\TestFramework\ObjectManager; |
| 10 | +use Magento\TestFramework\TestCase\WebapiAbstract; |
| 11 | +use Magento\Quote\Api\Data\AddressInterface; |
| 12 | + |
| 13 | +class GuestShipmentEstimationWithExtensionAttributesTest extends WebapiAbstract |
| 14 | +{ |
| 15 | + const SERVICE_VERSION = 'V1'; |
| 16 | + const SERVICE_NAME = 'quoteGuestShipmentEstimationV1'; |
| 17 | + const RESOURCE_PATH = '/V1/guest-carts/'; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var ObjectManager |
| 21 | + */ |
| 22 | + private $objectManager; |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @magentoAppIsolation enabled |
| 31 | + * @magentoDbIsolation disabled |
| 32 | + * @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_free_shipping.php |
| 33 | + * @magentoApiDataFixture Magento/Sales/_files/quote.php |
| 34 | + */ |
| 35 | + public function testEstimateByExtendedAddress(): void |
| 36 | + { |
| 37 | + /** @var \Magento\Quote\Model\Quote $quote */ |
| 38 | + $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); |
| 39 | + $quote->load('test01', 'reserved_order_id'); |
| 40 | + $cartId = $quote->getId(); |
| 41 | + if (!$cartId) { |
| 42 | + $this->fail('quote fixture failed'); |
| 43 | + } |
| 44 | + |
| 45 | + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ |
| 46 | + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() |
| 47 | + ->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) |
| 48 | + ->create(); |
| 49 | + $quoteIdMask->load($cartId, 'quote_id'); |
| 50 | + //Use masked cart Id |
| 51 | + $cartId = $quoteIdMask->getMaskedId(); |
| 52 | + $serviceInfo = [ |
| 53 | + 'rest' => [ |
| 54 | + 'resourcePath' => '/V1/guest-carts/' . $cartId . '/estimate-shipping-methods', |
| 55 | + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, |
| 56 | + ], |
| 57 | + 'soap' => [ |
| 58 | + 'service' => self::SERVICE_NAME, |
| 59 | + 'serviceVersion' => 'V1', |
| 60 | + 'operation' => self::SERVICE_NAME . 'EstimateByExtendedAddress', |
| 61 | + ], |
| 62 | + ]; |
| 63 | + if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { |
| 64 | + /** @var \Magento\Quote\Model\Quote\Address $address */ |
| 65 | + $address = $quote->getShippingAddress(); |
| 66 | + |
| 67 | + $data = [ |
| 68 | + AddressInterface::KEY_ID => (int)$address->getId(), |
| 69 | + AddressInterface::KEY_REGION => $address->getRegion(), |
| 70 | + AddressInterface::KEY_REGION_ID => $address->getRegionId(), |
| 71 | + AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), |
| 72 | + AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), |
| 73 | + AddressInterface::KEY_STREET => $address->getStreet(), |
| 74 | + AddressInterface::KEY_COMPANY => $address->getCompany(), |
| 75 | + AddressInterface::KEY_TELEPHONE => $address->getTelephone(), |
| 76 | + AddressInterface::KEY_POSTCODE => $address->getPostcode(), |
| 77 | + AddressInterface::KEY_CITY => $address->getCity(), |
| 78 | + AddressInterface::KEY_FIRSTNAME => $address->getFirstname(), |
| 79 | + AddressInterface::KEY_LASTNAME => $address->getLastname(), |
| 80 | + AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(), |
| 81 | + AddressInterface::KEY_EMAIL => $address->getEmail(), |
| 82 | + AddressInterface::SAME_AS_BILLING => $address->getSameAsBilling(), |
| 83 | + AddressInterface::CUSTOMER_ADDRESS_ID => $address->getCustomerAddressId(), |
| 84 | + AddressInterface::SAVE_IN_ADDRESS_BOOK => $address->getSaveInAddressBook(), |
| 85 | + ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => [ |
| 86 | + 'discounts' => [] |
| 87 | + ] |
| 88 | + ]; |
| 89 | + |
| 90 | + $requestData = [ |
| 91 | + 'cartId' => $cartId, |
| 92 | + 'address' => $data |
| 93 | + ]; |
| 94 | + } else { |
| 95 | + |
| 96 | + $requestData = [ |
| 97 | + 'address' => [ |
| 98 | + 'country_id' => "US", |
| 99 | + 'postcode' => null, |
| 100 | + 'region' => null, |
| 101 | + 'region_id' => null, |
| 102 | + 'extension_attributes' => [ |
| 103 | + 'discounts' => [] |
| 104 | + ] |
| 105 | + ] |
| 106 | + ]; |
| 107 | + } |
| 108 | + |
| 109 | + // Cart must be anonymous (see fixture) |
| 110 | + $this->assertEmpty($quote->getCustomerId()); |
| 111 | + |
| 112 | + $result = $this->_webApiCall($serviceInfo, $requestData); |
| 113 | + |
| 114 | + $this->assertNotEmpty($result); |
| 115 | + $this->assertEquals(1, count($result)); |
| 116 | + foreach ($result as $rate) { |
| 117 | + $this->assertEquals("flatrate", $rate['carrier_code']); |
| 118 | + $this->assertEquals(0, $rate['amount']); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments