Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Message "The Cart includes virtual product(s) only, so a shipping add ress is not used." #406

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Quote\Model\ShippingAddressManagementInterface;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
use Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCartInterface;
use Magento\Framework\Exception\LocalizedException;

/**
* Class SetShippingAddressesOnCart
Expand Down Expand Up @@ -79,7 +80,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());

$this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses);
try {
$this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses);
} catch (LocalizedException $e) {
throw new GraphQlInputException(__($e->getMessage()));
}

return [
'cart' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,47 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress()
$this->graphQlQuery($query, [], '', $this->getHeaderMap('[email protected]'));
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
* @expectedException \Exception
* @expectedExceptionMessage The Cart includes virtual product(s) only, so a shipping address is not used.
*/
public function testSetShippingAddressByRegisteredCustomerWithVirtualCart()
{
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_virtual_product');

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "$maskedQuoteId"
shipping_addresses: [
{
customer_address_id: 1
}
]
}
) {
cart {
shipping_addresses {
firstname
lastname
company
street
city
postcode
telephone
}
}
}
}
QUERY;
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}


/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down