From c8c4e06b23a41beb24c347829b41b623c14b70db Mon Sep 17 00:00:00 2001 From: Michal Derlatka Date: Sat, 27 Jun 2020 22:54:37 +0200 Subject: [PATCH] magento/magento2#26107: Exception message on cart with no shipment items --- .../Magento/Quote/Model/ShippingAddressManagement.php | 2 +- .../Model/Cart/AssignShippingAddressToCart.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Quote/Model/ShippingAddressManagement.php b/app/code/Magento/Quote/Model/ShippingAddressManagement.php index 45b3313d32114..b9edcc13d0077 100644 --- a/app/code/Magento/Quote/Model/ShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/ShippingAddressManagement.php @@ -88,7 +88,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres $quote = $this->quoteRepository->getActive($cartId); if ($quote->isVirtual()) { throw new NoSuchEntityException( - __('Shipping address is not allowed on cart: cart contains no items for shipment.') + __('The Cart includes virtual product(s) only, so a shipping address is not used.') ); } diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php index 4dbcfad31e84c..2d1b57cf69836 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php @@ -49,7 +49,14 @@ public function execute( try { $this->shippingAddressManagement->assign($cart->getId(), $shippingAddress); } catch (NoSuchEntityException $e) { - throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + if ($cart->getIsVirtual()) { + throw new GraphQlNoSuchEntityException( + __('Shipping address is not allowed on cart: cart contains no items for shipment.'), + $e + ); + } else { + throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); + } } catch (InputException $e) { throw new GraphQlInputException(__($e->getMessage()), $e); }