Skip to content

Commit aa16f06

Browse files
Validate shipping method placing an order in GraphQL
1 parent 2a55516 commit aa16f06

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

app/code/Magento/Quote/Model/ValidationRules/ShippingMethodValidationRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function validate(Quote $quote): array
4949
$shippingAddress->setStoreId($quote->getStoreId());
5050
$shippingMethod = $shippingAddress->getShippingMethod();
5151
$shippingRate = $shippingAddress->getShippingRateByCode($shippingMethod);
52-
$validationResult = $shippingMethod && $shippingRate;
52+
$validationResult = $shippingMethod && $shippingRate && $shippingAddress->requestShippingRates();
5353
if (!$validationResult) {
5454
$validationErrors = [__($this->generalMessage)];
5555
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/PlaceOrderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,32 @@ public function testPlaceOrderWithNoShippingMethod()
157157
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
158158
}
159159

160+
161+
/**
162+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
163+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
164+
* @magentoConfigFixture default_store carriers/flatrate/active 1
165+
* @magentoConfigFixture default_store payment/checkmo/active 1
166+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
167+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
168+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
169+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
170+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
171+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
172+
* @magentoConfigFixture default_store carriers/flatrate/active 0
173+
*/
174+
public function testPlaceOrderWithDisabledShippingMethod()
175+
{
176+
$reservedOrderId = 'test_quote';
177+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
178+
$query = $this->getQuery($maskedQuoteId);
179+
180+
self::expectExceptionMessage(
181+
'Unable to place order: The shipping method is missing. Select the shipping method and try again'
182+
);
183+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
184+
}
185+
160186
/**
161187
* @magentoApiDataFixture Magento/Customer/_files/customer.php
162188
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php

0 commit comments

Comments
 (0)