Skip to content

Commit 7c21b3b

Browse files
author
vitaliyboyko
committed
graphQl: removed set shipping addresses chain, using di preference instead
1 parent 55b6f4e commit 7c21b3b

File tree

5 files changed

+55
-62
lines changed

5 files changed

+55
-62
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCart;
8+
namespace Magento\QuoteGraphQl\Model\Cart;
99

1010
use Magento\Authorization\Model\UserContextInterface;
1111
use Magento\Customer\Api\Data\AddressInterface;
@@ -16,12 +16,11 @@
1616
use Magento\Quote\Model\Quote\Address;
1717
use Magento\Quote\Model\ShippingAddressManagementInterface;
1818
use Magento\Customer\Api\AddressRepositoryInterface;
19-
use Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCartInterface;
2019

2120
/**
2221
* Set single shipping address for a specified shopping cart
2322
*/
24-
class SingleShippingAddressProcessor implements SetShippingAddressesOnCartInterface
23+
class SetShippingAddressOnCart implements SetShippingAddressesOnCartInterface
2524
{
2625
/**
2726
* @var ShippingAddressManagementInterface
@@ -59,7 +58,9 @@ public function __construct(
5958
public function execute(ContextInterface $context, CartInterface $cart, array $shippingAddresses): void
6059
{
6160
if (count($shippingAddresses) > 1) {
62-
return;
61+
throw new GraphQlInputException(
62+
__('Multiple addresses do not allowed here!')
63+
);
6364
}
6465
$shippingAddress = current($shippingAddresses);
6566
$customerAddressId = $shippingAddress['customer_address_id'] ?? null;

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"magento/module-quote": "*",
99
"magento/module-catalog": "*",
1010
"magento/module-store": "*",
11-
"magento/module-checkout": "*"
11+
"magento/module-checkout": "*",
12+
"magento/module-customer": "*",
13+
"magento/module-authorization": "*"
1214
},
1315
"suggest": {
1416
"magento/module-graph-ql": "*"

app/code/Magento/QuoteGraphQl/etc/graphql/di.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCartInterface"
10-
type="Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCart" />
11-
<type name="Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCartInterface">
12-
<arguments>
13-
<argument name="shippingAddressProcessors" xsi:type="array">
14-
<item name="singleShippingAddress" xsi:type="object">Magento\QuoteGraphQl\Model\Cart\SetShippingAddressesOnCart\SingleShippingAddressProcessor</item>
15-
</argument>
16-
</arguments>
17-
</type>
10+
type="Magento\QuoteGraphQl\Model\Cart\SetShippingAddressOnCart" />
1811
<virtualType name="multishippingPaymentSpecification" type="Magento\Payment\Model\Method\Specification\Composite">
1912
<arguments>
2013
<argument name="specifications" xsi:type="array">

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,52 @@ public function testSetSavedShippingAddressOnCartByGuest()
143143
$this->graphQlQuery($query);
144144
}
145145

146+
/**
147+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
148+
* @magentoConfigFixture default_store multishipping/options/checkout_multiple 0
149+
*/
150+
public function testSetMultipleShippingAddressesOnCartByGuest()
151+
{
152+
$this->quoteResource->load(
153+
$this->quote,
154+
'test_order_with_simple_product_without_address',
155+
'reserved_order_id'
156+
);
157+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
158+
159+
$query = <<<QUERY
160+
mutation {
161+
setShippingAddressesOnCart(
162+
input: {
163+
cart_id: "$maskedQuoteId"
164+
shipping_addresses: [
165+
{
166+
customer_address_id: 1
167+
},
168+
{
169+
customer_address_id: 1
170+
}
171+
]
172+
}
173+
) {
174+
cart {
175+
addresses {
176+
firstname
177+
lastname
178+
company
179+
street
180+
city
181+
postcode
182+
telephone
183+
}
184+
}
185+
}
186+
}
187+
QUERY;
188+
self::expectExceptionMessage('Multiple addresses do not allowed here!');
189+
$this->graphQlQuery($query);
190+
}
191+
146192
/**
147193
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
148194
*/

0 commit comments

Comments
 (0)