Skip to content

Commit 9f431a7

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-2520' into Tier4-PR-Delivery-11-18-23
2 parents d7690e8 + 13c1af0 commit 9f431a7

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddresses.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5454
$cart = $value['model'];
5555

5656
$addressesData = [];
57+
58+
if ($cart->getIsVirtual()) {
59+
return $addressesData;
60+
}
61+
5762
$shippingAddresses = $cart->getAllShippingAddresses();
5863

5964
if (count($shippingAddresses)) {
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\GraphQl\Quote\Guest;
20+
21+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
22+
use Magento\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku;
23+
use Magento\TestFramework\Helper\Bootstrap;
24+
use Magento\TestFramework\TestCase\GraphQlAbstract;
25+
26+
/**
27+
* Test for getting is_virtual from cart
28+
*/
29+
class GetShippingAddressWhenCartIsVirtualTest extends GraphQlAbstract
30+
{
31+
/**
32+
* @var GetMaskedQuoteIdByReservedOrderId
33+
*/
34+
private $getMaskedQuoteIdByReservedOrderId;
35+
36+
/**
37+
* @var GetQuoteItemIdByReservedQuoteIdAndSku
38+
*/
39+
private $getQuoteItemIdByReservedQuoteIdAndSku;
40+
41+
protected function setUp(): void
42+
{
43+
$objectManager = Bootstrap::getObjectManager();
44+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
45+
$this->getQuoteItemIdByReservedQuoteIdAndSku = $objectManager->get(
46+
GetQuoteItemIdByReservedQuoteIdAndSku::class
47+
);
48+
}
49+
50+
/**
51+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
52+
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
53+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
54+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
55+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
56+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
57+
*/
58+
public function testGetShippingAddressForVirtualCart()
59+
{
60+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
61+
$query = $this->getQuery($maskedQuoteId);
62+
$response = $this->graphQlQuery($query);
63+
$itemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');
64+
65+
$expectedShippingAddressData = [
66+
'firstname' => 'John',
67+
'lastname' => 'Smith',
68+
'company' => 'CompanyName',
69+
'street' => [
70+
'Green str, 67'
71+
],
72+
'city' => 'CityM',
73+
'region' => [
74+
'code' => 'AL',
75+
'label' => 'Alabama',
76+
],
77+
'postcode' => '75477',
78+
'country' => [
79+
'code' => 'US',
80+
'label' => 'US',
81+
],
82+
'telephone' => '3468676',
83+
'__typename' => 'ShippingCartAddress',
84+
];
85+
86+
$this->assertArrayHasKey('cart', $response);
87+
$this->assertArrayHasKey('is_virtual', $response['cart']);
88+
$this->assertFalse($response['cart']['is_virtual']);
89+
$this->assertArrayHasKey('shipping_addresses', $response['cart']);
90+
$this->assertEquals($expectedShippingAddressData, current($response['cart']['shipping_addresses']));
91+
92+
$query2 = $this->getQueryForItemRemove($maskedQuoteId, $itemId);
93+
$this->graphQlMutation($query2);
94+
$response = $this->graphQlQuery($query);
95+
96+
$this->assertArrayHasKey('cart', $response);
97+
$this->assertArrayHasKey('is_virtual', $response['cart']);
98+
$this->assertTrue($response['cart']['is_virtual']);
99+
$this->assertArrayHasKey('shipping_addresses', $response['cart']);
100+
$this->assertFalse(current($response['cart']['shipping_addresses']));
101+
}
102+
103+
/**
104+
* @param string $maskedQuoteId
105+
* @return string
106+
*/
107+
private function getQuery(string $maskedQuoteId): string
108+
{
109+
return <<<QUERY
110+
{
111+
cart(cart_id: "$maskedQuoteId") {
112+
is_virtual
113+
total_quantity
114+
items {
115+
id
116+
product {
117+
name
118+
sku
119+
}
120+
quantity
121+
errors {
122+
code
123+
message
124+
}
125+
}
126+
shipping_addresses {
127+
firstname
128+
lastname
129+
company
130+
street
131+
city
132+
region
133+
{
134+
code
135+
label
136+
}
137+
postcode
138+
country
139+
{
140+
code
141+
label
142+
}
143+
telephone
144+
__typename
145+
}
146+
}
147+
}
148+
QUERY;
149+
}
150+
151+
/**
152+
* @param string $maskedQuoteId
153+
* @param int $itemId
154+
* @return string
155+
*/
156+
private function getQueryForItemRemove(string $maskedQuoteId, int $itemId): string
157+
{
158+
return <<<QUERY
159+
mutation {
160+
removeItemFromCart(
161+
input: {
162+
cart_id: "{$maskedQuoteId}"
163+
cart_item_id: {$itemId}
164+
}
165+
) {
166+
cart {
167+
items {
168+
quantity
169+
}
170+
}
171+
}
172+
}
173+
QUERY;
174+
}
175+
}

0 commit comments

Comments
 (0)