Skip to content

Commit 5d24f19

Browse files
ENGCOM-7796: #26107: Exception message on cart with no shipment items #28904
- Merge Pull Request #28904 from michalderlatka/magento2:26107_virtual_product_exception_message - Merged commits: 1. 1091a30 2. c8c4e06 3. 77bd613
2 parents 735579d + 77bd613 commit 5d24f19

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/AssignShippingAddressToCart.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Magento\Quote\Model\ShippingAddressManagementInterface;
1717

1818
/**
19-
* Assign shipping address to cart
19+
* Assigning shipping address to cart
2020
*/
2121
class AssignShippingAddressToCart
2222
{
@@ -49,7 +49,14 @@ public function execute(
4949
try {
5050
$this->shippingAddressManagement->assign($cart->getId(), $shippingAddress);
5151
} catch (NoSuchEntityException $e) {
52-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
52+
if ($cart->getIsVirtual()) {
53+
throw new GraphQlNoSuchEntityException(
54+
__('Shipping address is not allowed on cart: cart contains no items for shipment.'),
55+
$e
56+
);
57+
} else {
58+
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
59+
}
5360
} catch (InputException $e) {
5461
throw new GraphQlInputException(__($e->getMessage()), $e);
5562
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testSetNewShippingAddressOnCartWithSimpleProduct()
149149
public function testSetNewShippingAddressOnCartWithVirtualProduct()
150150
{
151151
$this->expectException(\Exception::class);
152-
$this->expectExceptionMessage('The Cart includes virtual product(s) only, so a shipping address is not used.');
152+
$this->expectExceptionMessage('Shipping address is not allowed on cart: cart contains no items for shipment.');
153153

154154
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
155155

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingAddressOnCartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testSetNewShippingAddressOnCartWithSimpleProduct()
9797
public function testSetNewShippingAddressOnCartWithVirtualProduct()
9898
{
9999
$this->expectException(\Exception::class);
100-
$this->expectExceptionMessage('The Cart includes virtual product(s) only, so a shipping address is not used.');
100+
$this->expectExceptionMessage('Shipping address is not allowed on cart: cart contains no items for shipment.');
101101

102102
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
103103

0 commit comments

Comments
 (0)