Skip to content

Commit b78aa2a

Browse files
committed
Cannot return null for non-nullable field AvailableShippingMethod.method_code when no shipping methods are available
1 parent 8f45cf8 commit b78aa2a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/AvailableShippingMethods.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1314
use Magento\Framework\GraphQl\Query\ResolverInterface;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1516
use Magento\Quote\Api\Data\ShippingMethodInterface;
@@ -65,13 +66,19 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6566
$shippingRates = $address->getGroupedAllShippingRates();
6667
foreach ($shippingRates as $carrierRates) {
6768
foreach ($carrierRates as $rate) {
68-
$methods[] = $this->dataObjectConverter->toFlatArray(
69+
$method = $this->dataObjectConverter->toFlatArray(
6970
$this->shippingMethodConverter->modelToDataObject($rate, $cart->getQuoteCurrencyCode()),
7071
[],
7172
ShippingMethodInterface::class
7273
);
74+
if ($method['available'] && $method['error_message'] === "") {
75+
$methods[] = $method;
76+
}
7377
}
7478
}
79+
if (count($methods) === 0) {
80+
throw new GraphQlNoSuchEntityException(__(' This shipping method is not available. To use this shipping method, please contact us.'));
81+
}
7582
return $methods;
7683
}
7784
}

0 commit comments

Comments
 (0)