Skip to content

Commit 9cc293e

Browse files
🔃 [Magento Community Engineering] Community Contributions - GraphQL
Accepted Community Pull Requests: - magento/graphql-ce#971: Magento 2.3.2 - PWA - graphQl fetching Issue for phtml file called in static block magento#960 (by @XxXgeoXxX) - magento/graphql-ce#1028: magento/graphql-ce#1009: [Test Coverage] Cover exception in SalesGraphQl\Model\Resolver\Orders (by @atwixfirster) - magento/graphql-ce#943: graphQl-903: deprecated use_for_shipping in billing address schema (by @VitaliyBoyko) - magento/graphql-ce#899: graphQl-890: Replaced usage of the CartItemQuantity with the CartItem… (by @VitaliyBoyko) - magento/graphql-ce#1030: Extend coverage for CustomerGraphQL (by @TomashKhamlai) Fixed GitHub Issues: - magento/graphql-ce#1009: [Test Coverage] Cover exception in SalesGraphQl\Model\Resolver\Orders (reported by @TomashKhamlai) has been fixed in magento/graphql-ce#1028 by @atwixfirster in 2.3-develop branch Related commits: 1. 7b345f0 - magento/graphql-ce#890: [Checkout] Replace usage of CartItemQuantity with CartItemInterface (reported by @paliarush) has been fixed in magento/graphql-ce#899 by @VitaliyBoyko in 2.3-develop branch Related commits: 1. b3f510d 2. f7ab08e 3. 94e8f14 4. 77e3a9c 5. 863d178 6. 6297199 7. 795931f 8. c9c13a6 9. 8b51315 10. 344648f 11. b9f708b - magento/graphql-ce#1011: [Test Coverage] Extend coverage for CustomerGraphQL (reported by @TomashKhamlai) has been fixed in magento/graphql-ce#1030 by @TomashKhamlai in 2.3-develop branch Related commits: 1. 56382f1 2. a97ef07 3. 461763e
2 parents b6e9491 + e7616eb commit 9cc293e

File tree

14 files changed

+296
-30
lines changed

14 files changed

+296
-30
lines changed

app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getData(string $blockIdentifier): array
5656
);
5757
}
5858

59-
$renderedContent = $this->widgetFilter->filter($block->getContent());
59+
$renderedContent = $this->widgetFilter->filterDirective($block->getContent());
6060

6161
$blockData = [
6262
BlockInterface::BLOCK_ID => $block->getId(),

app/code/Magento/CustomerGraphQl/Model/Customer/Address/ExtractCustomerAddressData.php

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function execute(AddressInterface $address): array
105105
foreach ($addressData[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] as $attribute) {
106106
$isArray = false;
107107
if (is_array($attribute['value'])) {
108+
// @ignoreCoverageStart
108109
$isArray = true;
109110
foreach ($attribute['value'] as $attributeValue) {
110111
if (is_array($attributeValue)) {
@@ -116,6 +117,7 @@ public function execute(AddressInterface $address): array
116117
$customAttributes[$attribute['attribute_code']] = implode(',', $attribute['value']);
117118
continue;
118119
}
120+
// @ignoreCoverageEnd
119121
}
120122
if ($isArray) {
121123
continue;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public function __construct(
3939
*
4040
* @param CartInterface $cart
4141
* @param AddressInterface $billingAddress
42-
* @param bool $useForShipping
42+
* @param bool $sameAsShipping
4343
* @throws GraphQlInputException
4444
* @throws GraphQlNoSuchEntityException
4545
*/
4646
public function execute(
4747
CartInterface $cart,
4848
AddressInterface $billingAddress,
49-
bool $useForShipping
49+
bool $sameAsShipping
5050
): void {
5151
try {
52-
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping);
52+
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $sameAsShipping);
5353
} catch (NoSuchEntityException $e) {
5454
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
5555
} catch (InputException $e) {

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,25 @@ public function execute(QuoteAddress $address): array
6161
return $addressData;
6262
}
6363

64-
$addressItemsData = [];
6564
foreach ($address->getAllItems() as $addressItem) {
6665
if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) {
6766
$itemId = $addressItem->getItemId();
6867
} else {
6968
$itemId = $addressItem->getQuoteItemId();
7069
}
71-
72-
$addressItemsData[] = [
70+
$productData = $addressItem->getProduct()->getData();
71+
$productData['model'] = $addressItem->getProduct();
72+
$addressData['cart_items'][] = [
7373
'cart_item_id' => $itemId,
7474
'quantity' => $addressItem->getQty()
7575
];
76+
$addressData['cart_items_v2'][] = [
77+
'id' => $itemId,
78+
'quantity' => $addressItem->getQty(),
79+
'product' => $productData,
80+
'model' => $addressItem,
81+
];
7682
}
77-
$addressData['cart_items'] = $addressItemsData;
78-
7983
return $addressData;
8084
}
8185
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
6565
{
6666
$customerAddressId = $billingAddressInput['customer_address_id'] ?? null;
6767
$addressInput = $billingAddressInput['address'] ?? null;
68-
$useForShipping = isset($billingAddressInput['use_for_shipping'])
68+
// Need to keep this for BC of `use_for_shipping` field
69+
$sameAsShipping = isset($billingAddressInput['use_for_shipping'])
6970
? (bool)$billingAddressInput['use_for_shipping'] : false;
71+
$sameAsShipping = isset($billingAddressInput['same_as_shipping'])
72+
? (bool)$billingAddressInput['same_as_shipping'] : $sameAsShipping;
7073

7174
if (null === $customerAddressId && null === $addressInput) {
7275
throw new GraphQlInputException(
@@ -81,15 +84,15 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
8184
}
8285

8386
$addresses = $cart->getAllShippingAddresses();
84-
if ($useForShipping && count($addresses) > 1) {
87+
if ($sameAsShipping && count($addresses) > 1) {
8588
throw new GraphQlInputException(
86-
__('Using the "use_for_shipping" option with multishipping is not possible.')
89+
__('Using the "same_as_shipping" option with multishipping is not possible.')
8790
);
8891
}
8992

9093
$billingAddress = $this->createBillingAddress($context, $customerAddressId, $addressInput);
9194

92-
$this->assignBillingAddressToCart->execute($cart, $billingAddress, $useForShipping);
95+
$this->assignBillingAddressToCart->execute($cart, $billingAddress, $sameAsShipping);
9396
}
9497

9598
/**

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

+8-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ input SetBillingAddressOnCartInput {
9696
input BillingAddressInput {
9797
customer_address_id: Int
9898
address: CartAddressInput
99-
use_for_shipping: Boolean
99+
use_for_shipping: Boolean @doc(description: "Deprecated: use `same_as_shipping` field instead")
100+
same_as_shipping: Boolean @doc(description: "Set billing address same as shipping")
100101
}
101102

102103
input CartAddressInput {
@@ -219,18 +220,19 @@ interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Mo
219220
type ShippingCartAddress implements CartAddressInterface {
220221
available_shipping_methods: [AvailableShippingMethod] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\AvailableShippingMethods")
221222
selected_shipping_method: SelectedShippingMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddress\\SelectedShippingMethod")
222-
items_weight: Float
223-
cart_items: [CartItemQuantity]
224223
customer_notes: String
224+
items_weight: Float @deprecated(reason: "This information shoud not be exposed on frontend")
225+
cart_items: [CartItemQuantity] @deprecated(reason: "`cart_items_v2` should be used instead")
226+
cart_items_v2: [CartItemInterface]
225227
}
226228

227229
type BillingCartAddress implements CartAddressInterface {
228230
customer_notes: String @deprecated (reason: "The field is used only in shipping address")
229231
}
230232

231-
type CartItemQuantity {
232-
cart_item_id: Int!
233-
quantity: Float!
233+
type CartItemQuantity @doc(description:"Deprecated: `cart_items` field of `ShippingCartAddress` returns now `CartItemInterface` instead of `CartItemQuantity`") {
234+
cart_item_id: Int! @deprecated(reason: "`cart_items` field of `ShippingCartAddress` returns now `CartItemInterface` instead of `CartItemQuantity`")
235+
quantity: Float! @deprecated(reason: "`cart_items` field of `ShippingCartAddress` returns now `CartItemInterface` instead of `CartItemQuantity`")
234236
}
235237

236238
type CartAddressRegion {

app/code/Magento/Widget/Model/Template/FilterEmulate.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Widget\Model\Template;
79

10+
/**
11+
* Class FilterEmulate
12+
*
13+
* @package Magento\Widget\Model\Template
14+
*/
815
class FilterEmulate extends Filter
916
{
1017
/**
1118
* Generate widget with emulation frontend area
1219
*
1320
* @param string[] $construction
14-
* @return string
21+
*
22+
* @return mixed|string
23+
* @throws \Exception
1524
*/
1625
public function widgetDirective($construction)
1726
{
1827
return $this->_appState->emulateAreaCode('frontend', [$this, 'generateWidget'], [$construction]);
1928
}
29+
30+
/**
31+
* Filter the string as template with frontend area emulation
32+
*
33+
* @param string $value
34+
*
35+
* @return string
36+
* @throws \Exception
37+
*/
38+
public function filterDirective($value) : string
39+
{
40+
return $this->_appState->emulateAreaCode(
41+
\Magento\Framework\App\Area::AREA_FRONTEND,
42+
[$this, 'filter'],
43+
[$value]
44+
);
45+
}
2046
}

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

+43
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,49 @@ public function testUpdateCustomerAddressWithMissingAttribute()
176176
$this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
177177
}
178178

179+
/**
180+
* Test custom attributes of the customer's address
181+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
182+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
183+
* @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_address_custom_attribute.php
184+
*/
185+
public function testUpdateCustomerAddressHasCustomAttributes()
186+
{
187+
$userName = '[email protected]';
188+
$password = 'password';
189+
$addressId = 1;
190+
$attributes = [
191+
[
192+
'attribute_code' => 'custom_attribute1',
193+
'value'=> '[new-value1,new-value2]'
194+
],
195+
[
196+
'attribute_code' => 'custom_attribute2',
197+
'value'=> '"new-value3"'
198+
]
199+
];
200+
$attributesFragment = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($attributes));
201+
$mutation
202+
= <<<MUTATION
203+
mutation {
204+
updateCustomerAddress(
205+
id: {$addressId}
206+
input: {
207+
custom_attributes: {$attributesFragment}
208+
}
209+
) {
210+
custom_attributes {
211+
attribute_code
212+
value
213+
}
214+
}
215+
}
216+
MUTATION;
217+
218+
$response = $this->graphQlMutation($mutation, [], '', $this->getCustomerAuthHeaders($userName, $password));
219+
$this->assertEquals($attributes, $response['updateCustomerAddress']['custom_attributes']);
220+
}
221+
179222
/**
180223
* Verify the fields for Customer address
181224
*

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

+56
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,36 @@ public function testAddSimpleProductToCart()
5050
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
5151

5252
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
53+
self::assertArrayHasKey('shipping_addresses', $response['addSimpleProductsToCart']['cart']);
54+
self::assertEmpty($response['addSimpleProductsToCart']['cart']['shipping_addresses']);
5355
self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
5456
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
57+
self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]);
58+
59+
self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
60+
$price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price'];
61+
self::assertArrayHasKey('value', $price);
62+
self::assertEquals(10, $price['value']);
63+
self::assertArrayHasKey('currency', $price);
64+
self::assertEquals('USD', $price['currency']);
65+
66+
self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
67+
$rowTotal = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total'];
68+
self::assertArrayHasKey('value', $rowTotal);
69+
self::assertEquals(20, $rowTotal['value']);
70+
self::assertArrayHasKey('currency', $rowTotal);
71+
self::assertEquals('USD', $rowTotal['currency']);
72+
73+
self::assertArrayHasKey(
74+
'row_total_including_tax',
75+
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']
76+
);
77+
$rowTotalIncludingTax =
78+
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax'];
79+
self::assertArrayHasKey('value', $rowTotalIncludingTax);
80+
self::assertEquals(20, $rowTotalIncludingTax['value']);
81+
self::assertArrayHasKey('currency', $rowTotalIncludingTax);
82+
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
5583
}
5684

5785
/**
@@ -262,6 +290,34 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity):
262290
product {
263291
sku
264292
}
293+
prices {
294+
price {
295+
value
296+
currency
297+
}
298+
row_total {
299+
value
300+
currency
301+
}
302+
row_total_including_tax {
303+
value
304+
currency
305+
}
306+
}
307+
}
308+
shipping_addresses {
309+
firstname
310+
lastname
311+
company
312+
street
313+
city
314+
postcode
315+
telephone
316+
country {
317+
code
318+
label
319+
}
320+
__typename
265321
}
266322
}
267323
}

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function testSetNewBillingAddress()
101101
country_code: "US"
102102
telephone: "88776655"
103103
}
104+
same_as_shipping: true
104105
}
105106
}
106107
) {
@@ -119,6 +120,20 @@ public function testSetNewBillingAddress()
119120
}
120121
__typename
121122
}
123+
shipping_addresses {
124+
firstname
125+
lastname
126+
company
127+
street
128+
city
129+
postcode
130+
telephone
131+
country {
132+
code
133+
label
134+
}
135+
__typename
136+
}
122137
}
123138
}
124139
}
@@ -129,10 +144,15 @@ public function testSetNewBillingAddress()
129144
$cartResponse = $response['setBillingAddressOnCart']['cart'];
130145
self::assertArrayHasKey('billing_address', $cartResponse);
131146
$billingAddressResponse = $cartResponse['billing_address'];
147+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
148+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
132149
$this->assertNewAddressFields($billingAddressResponse);
150+
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
133151
}
134152

135153
/**
154+
* Test case for deprecated `use_for_shipping` param.
155+
*
136156
* @magentoApiDataFixture Magento/Customer/_files/customer.php
137157
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
138158
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
@@ -389,7 +409,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
389409
input: {
390410
cart_id: "$maskedQuoteId"
391411
billing_address: {
392-
use_for_shipping: true
412+
same_as_shipping: true
393413
}
394414
}
395415
) {
@@ -415,7 +435,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
415435
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
416436
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php
417437
*/
418-
public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
438+
public function testSetNewBillingAddressWithSameAsShippingAndMultishipping()
419439
{
420440
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
421441

@@ -436,7 +456,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
436456
country_code: "US"
437457
telephone: "88776655"
438458
}
439-
use_for_shipping: true
459+
same_as_shipping: true
440460
}
441461
}
442462
) {
@@ -450,7 +470,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
450470
QUERY;
451471

452472
self::expectExceptionMessage(
453-
'Using the "use_for_shipping" option with multishipping is not possible.'
473+
'Using the "same_as_shipping" option with multishipping is not possible.'
454474
);
455475
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
456476
}

0 commit comments

Comments
 (0)