Skip to content

Commit 2100cc7

Browse files
committed
ACP2E-2520: Once Cart Become Virtual Cart after removing physical products it still returns shipping method and address in Cart Quote Graphql response
1 parent c5628dd commit 2100cc7

File tree

1 file changed

+191
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)