Skip to content

Commit 19c196e

Browse files
authored
Merge pull request #3972 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents b138617 + f13c1ba commit 19c196e

File tree

6 files changed

+348
-213
lines changed

6 files changed

+348
-213
lines changed

app/code/Magento/CatalogGraphQl/Model/Category/DepthCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function calculate(FieldNode $fieldNode) : int
2626
$depth = count($selections) ? 1 : 0;
2727
$childrenDepth = [0];
2828
foreach ($selections as $node) {
29-
if ($node->kind === 'InlineFragment') {
29+
if ($node->kind === 'InlineFragment' || null !== $node->alias) {
3030
continue;
3131
}
3232

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ input ProductFilterInput @doc(description: "ProductFilterInput defines the filte
460460
description: FilterTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
461461
short_description: FilterTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
462462
price: FilterTypeInput @doc(description: "The price of an item")
463-
special_price: FilterTypeInput @doc(description: "The discounted price of the product")
463+
special_price: FilterTypeInput @doc(description: "The discounted price of the product. Do not include the currency code.")
464464
special_from_date: FilterTypeInput @doc(description: "The beginning date that a product has a special price")
465465
special_to_date: FilterTypeInput @doc(description: "The end date that a product has a special price")
466466
weight: FilterTypeInput @doc(description: "The weight of the item, in units defined by the store")
@@ -477,7 +477,6 @@ input ProductFilterInput @doc(description: "ProductFilterInput defines the filte
477477
custom_layout_update: FilterTypeInput @doc(description: "XML code that is applied as a layout update to the product page")
478478
min_price: FilterTypeInput @doc(description:"The numeric minimal price of the product. Do not include the currency code.")
479479
max_price: FilterTypeInput @doc(description:"The numeric maximal price of the product. Do not include the currency code.")
480-
special_price: FilterTypeInput @doc(description:"The numeric special price of the product. Do not include the currency code.")
481480
category_id: FilterTypeInput @doc(description: "Category ID the product belongs to")
482481
options_container: FilterTypeInput @doc(description: "If the product has multiple options, determines where they appear on the product page")
483482
required_options: FilterTypeInput @doc(description: "Indicates whether the product has required options")

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\GraphQl\Catalog;
99

1010
use Magento\Catalog\Api\Data\CategoryInterface;
11+
use Magento\Catalog\Model\CategoryRepository;
1112
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1213
use Magento\Framework\DataObject;
1314
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
@@ -16,16 +17,25 @@
1617
use Magento\Catalog\Api\ProductRepositoryInterface;
1718
use Magento\TestFramework\ObjectManager;
1819

20+
/**
21+
* Test loading of category tree
22+
*/
1923
class CategoryTest extends GraphQlAbstract
2024
{
2125
/**
2226
* @var \Magento\TestFramework\ObjectManager
2327
*/
2428
private $objectManager;
2529

30+
/**
31+
* @var CategoryRepository
32+
*/
33+
private $categoryRepository;
34+
2635
protected function setUp()
2736
{
2837
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
38+
$this->categoryRepository = $this->objectManager->get(CategoryRepository::class);
2939
}
3040

3141
/**
@@ -103,6 +113,42 @@ public function testCategoriesTree()
103113
);
104114
}
105115

116+
/**
117+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
118+
*/
119+
public function testCategoriesTreeWithDisabledCategory()
120+
{
121+
$category = $this->categoryRepository->get(3);
122+
$category->setIsActive(false);
123+
$this->categoryRepository->save($category);
124+
125+
$rootCategoryId = 2;
126+
$query = <<<QUERY
127+
{
128+
category(id: {$rootCategoryId}) {
129+
id
130+
name
131+
level
132+
description
133+
children {
134+
id
135+
name
136+
productImagePreview: products(pageSize: 1) {
137+
items {
138+
id
139+
}
140+
}
141+
}
142+
}
143+
}
144+
QUERY;
145+
$response = $this->graphQlQuery($query);
146+
147+
$this->assertArrayHasKey('category', $response);
148+
$this->assertArrayHasKey('children', $response['category']);
149+
$this->assertSame(6, count($response['category']['children']));
150+
}
151+
106152
/**
107153
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
108154
*/
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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\Customer;
9+
10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
11+
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
12+
use Magento\Integration\Api\CustomerTokenServiceInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\TestFramework\TestCase\GraphQlAbstract;
15+
16+
/**
17+
* Test for setting offline shipping methods on cart
18+
*/
19+
class SetOfflineShippingMethodsOnCartTest extends GraphQlAbstract
20+
{
21+
/**
22+
* @var GetMaskedQuoteIdByReservedOrderId
23+
*/
24+
private $getMaskedQuoteIdByReservedOrderId;
25+
26+
/**
27+
* @var GetQuoteShippingAddressIdByReservedQuoteId
28+
*/
29+
private $getQuoteShippingAddressIdByReservedQuoteId;
30+
31+
/**
32+
* @var CustomerTokenServiceInterface
33+
*/
34+
private $customerTokenService;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp()
40+
{
41+
$objectManager = Bootstrap::getObjectManager();
42+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
43+
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(
44+
GetQuoteShippingAddressIdByReservedQuoteId::class
45+
);
46+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
47+
}
48+
49+
/**
50+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
51+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
52+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
53+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
54+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
55+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php
56+
* @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php
57+
*
58+
* @param string $carrierCode
59+
* @param string $methodCode
60+
* @param float $amount
61+
* @param string $label
62+
* @dataProvider offlineShippingMethodDataProvider
63+
*/
64+
public function testSetOfflineShippingMethod(string $carrierCode, string $methodCode, float $amount, string $label)
65+
{
66+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
67+
$quoteAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute('test_quote');
68+
69+
$query = $this->getQuery(
70+
$maskedQuoteId,
71+
$methodCode,
72+
$carrierCode,
73+
$quoteAddressId
74+
);
75+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
76+
77+
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
78+
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
79+
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
80+
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
81+
82+
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
83+
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
84+
85+
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
86+
self::assertEquals($carrierCode, $shippingAddress['selected_shipping_method']['carrier_code']);
87+
88+
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
89+
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);
90+
91+
self::assertArrayHasKey('amount', $shippingAddress['selected_shipping_method']);
92+
self::assertEquals($amount, $shippingAddress['selected_shipping_method']['amount']);
93+
94+
self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']);
95+
self::assertEquals($label, $shippingAddress['selected_shipping_method']['label']);
96+
}
97+
98+
/**
99+
* @return array
100+
*/
101+
public function offlineShippingMethodDataProvider(): array
102+
{
103+
return [
104+
'flatrate_flatrate' => ['flatrate', 'flatrate', 10, 'Flat Rate - Fixed'],
105+
'tablerate_bestway' => ['tablerate', 'bestway', 10, 'Best Way - Table Rate'],
106+
'freeshipping_freeshipping' => ['freeshipping', 'freeshipping', 0, 'Free Shipping - Free'],
107+
];
108+
}
109+
110+
/**
111+
* @param string $maskedQuoteId
112+
* @param string $shippingMethodCode
113+
* @param string $shippingCarrierCode
114+
* @param int $shippingAddressId
115+
* @return string
116+
*/
117+
private function getQuery(
118+
string $maskedQuoteId,
119+
string $shippingMethodCode,
120+
string $shippingCarrierCode,
121+
int $shippingAddressId
122+
): string {
123+
return <<<QUERY
124+
mutation {
125+
setShippingMethodsOnCart(input:
126+
{
127+
cart_id: "$maskedQuoteId",
128+
shipping_methods: [{
129+
cart_address_id: $shippingAddressId
130+
carrier_code: "$shippingCarrierCode"
131+
method_code: "$shippingMethodCode"
132+
}]
133+
}) {
134+
cart {
135+
shipping_addresses {
136+
selected_shipping_method {
137+
carrier_code
138+
method_code
139+
amount
140+
label
141+
}
142+
}
143+
}
144+
}
145+
}
146+
QUERY;
147+
}
148+
149+
/**
150+
* @param string $username
151+
* @param string $password
152+
* @return array
153+
*/
154+
private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array
155+
{
156+
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password);
157+
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
158+
return $headerMap;
159+
}
160+
}

0 commit comments

Comments
 (0)