Skip to content

Commit fe8da2f

Browse files
committed
PWA-1720: Expose storefront properties of Catalog attributes
- added validations for newly added attribute storefront properties
1 parent 35ba942 commit fe8da2f

File tree

4 files changed

+101
-10
lines changed

4 files changed

+101
-10
lines changed

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testCustomAttributeMetadataOptions()
6060
label
6161
value
6262
}
63-
}
63+
}
6464
}
6565
}
6666
QUERY;
@@ -101,5 +101,48 @@ public function testCustomAttributeMetadataOptions()
101101
$actualOption = $actualAttributes[$index]['attribute_options'];
102102
$this->assertEquals($expectedOptions, $actualOption);
103103
}
104+
$queryWithStoreFrontProperties = <<<QUERY
105+
106+
{
107+
customAttributeMetadata(attributes:
108+
[
109+
{
110+
attribute_code:"dropdown_attribute",
111+
entity_type:"catalog_product"
112+
}
113+
]
114+
)
115+
{
116+
items
117+
{
118+
attribute_code
119+
attribute_type
120+
entity_type
121+
input_type
122+
storefront_properties {
123+
position
124+
use_in_search
125+
used_in_product_listing
126+
use_in_layered_navigation
127+
use_in_search_results_layered_navigation
128+
visible_on_catalog_storefront
129+
}
130+
}
131+
}
132+
}
133+
134+
QUERY;
135+
$response = $this->graphQlQuery($queryWithStoreFrontProperties);
136+
$this->assertArrayHasKey('storefront_properties', $response['customAttributeMetadata']['items'][0]);
137+
$actualStorefrontPropery = $response['customAttributeMetadata']['items'][0]['storefront_properties'];
138+
$expectedStorefrontProperties = [
139+
'position' => 0,
140+
'use_in_search' => false,
141+
'used_in_product_listing' => true,
142+
'use_in_layered_navigation' => 'NO',
143+
'use_in_search_results_layered_navigation' => false,
144+
'visible_on_catalog_storefront' => true
145+
];
146+
$this->assertEquals($expectedStorefrontProperties, $actualStorefrontPropery);
104147
}
105148
}

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

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ public function testComplexAttributeTypeResolver()
125125
attribute_type
126126
entity_type
127127
input_type
128+
storefront_properties {
129+
use_in_search
130+
used_in_product_listing
131+
use_in_layered_navigation
132+
use_in_search_results_layered_navigation
133+
visible_on_catalog_storefront
134+
}
128135
}
129136
}
130137
}
@@ -239,15 +246,41 @@ private function assertAttributeType(
239246
$attributeMetaDataItems = array_map(null, $actualResponse['customAttributeMetadata']['items'], $attributeTypes);
240247

241248
foreach ($attributeMetaDataItems as $itemIndex => $itemArray) {
242-
$this->assertResponseFields(
243-
$attributeMetaDataItems[$itemIndex][0],
244-
[
245-
"attribute_code" => $expectedAttributeCodes[$itemIndex],
246-
"attribute_type" => $attributeTypes[$itemIndex],
247-
"entity_type" => $entityTypes[$itemIndex],
248-
"input_type" => $inputTypes[$itemIndex]
249-
]
250-
);
249+
if($itemArray[0]['entity_type'] === 'catalog_category' || $itemArray[0]['entity_type'] ==='catalog_product') {
250+
$this->assertResponseFields(
251+
$attributeMetaDataItems[$itemIndex][0],
252+
[
253+
"attribute_code" => $expectedAttributeCodes[$itemIndex],
254+
"attribute_type" => $attributeTypes[$itemIndex],
255+
"entity_type" => $entityTypes[$itemIndex],
256+
"input_type" => $inputTypes[$itemIndex],
257+
"storefront_properties" => [
258+
'use_in_search' => false,
259+
'used_in_product_listing' => false,
260+
'use_in_layered_navigation' => 'NO',
261+
'use_in_search_results_layered_navigation' => false,
262+
'visible_on_catalog_storefront' => false,
263+
]
264+
]
265+
);
266+
}
267+
else {
268+
$this->assertNotEmpty($attributeMetaDataItems[$itemIndex][0]['storefront_properties']);
269+
// 5 fields are present
270+
$this->assertCount(5, $attributeMetaDataItems[$itemIndex][0]['storefront_properties']);
271+
unset($attributeMetaDataItems[$itemIndex][0]['storefront_properties']);
272+
$this->assertResponseFields(
273+
$attributeMetaDataItems[$itemIndex][0],
274+
[
275+
"attribute_code" => $expectedAttributeCodes[$itemIndex],
276+
"attribute_type" => $attributeTypes[$itemIndex],
277+
"entity_type" => $entityTypes[$itemIndex],
278+
"input_type" => $inputTypes[$itemIndex]
279+
]
280+
);
281+
282+
}
283+
251284
}
252285
}
253286
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function testLayeredNavigationForConfigurableProducts()
198198
'attribute_code' => $attribute->getAttributeCode(),
199199
'label' => $attribute->getDefaultFrontendLabel(),
200200
'count' => 2,
201+
'position' => 0,
201202
'options' => [
202203
[
203204
'label' => 'Option 1',
@@ -255,6 +256,7 @@ private function getQueryProductsWithArrayOfCustomAttributes($attributeCode, $fi
255256
attribute_code
256257
count
257258
label
259+
position
258260
options{
259261
label
260262
value
@@ -313,6 +315,7 @@ public function testFilterProductsByDropDownCustomAttribute()
313315
attribute_code
314316
count
315317
label
318+
position
316319
options
317320
{
318321
label
@@ -361,6 +364,7 @@ public function testFilterProductsByDropDownCustomAttribute()
361364
'attribute_code' => $attribute->getAttributeCode(),
362365
'count' => 1,
363366
'label' => $attribute->getDefaultFrontendLabel(),
367+
'position' => $attribute->getPosition(),
364368
'options' => [
365369
[
366370
'label' => 'Option 3',
@@ -428,6 +432,7 @@ public function testFilterProductsByMultiSelectCustomAttributes()
428432
attribute_code
429433
count
430434
label
435+
position
431436
options
432437
{
433438
label
@@ -445,6 +450,12 @@ public function testFilterProductsByMultiSelectCustomAttributes()
445450
$this->assertEquals(3, $response['products']['total_count']);
446451
$this->assertNotEmpty($response['products']['filters']);
447452
$this->assertNotEmpty($response['products']['aggregations']);
453+
$this->assertCount(2, $response['products']['aggregations']);
454+
$aggregations = $response['products']['aggregations'];
455+
foreach($aggregations as $aggregation)
456+
{
457+
$this->assertNotEmpty($aggregations['position']);
458+
}
448459
}
449460

450461
/**
@@ -515,6 +526,7 @@ public function testSearchAndFilterByCustomAttribute()
515526
attribute_code
516527
count
517528
label
529+
position
518530
options
519531
{
520532
count
@@ -588,6 +600,7 @@ public function testSearchAndFilterByCustomAttribute()
588600
'attribute_code' => $attribute_code,
589601
'count' => 1,
590602
'label' => 'Second Test Configurable',
603+
'position' => 1,
591604
'options' => [
592605
[
593606
'count' => 3,
@@ -663,6 +676,7 @@ public function testFilterByCategoryIdAndCustomAttribute()
663676
attribute_code
664677
count
665678
label
679+
position
666680
options
667681
{
668682
count

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_layered_navigation_custom_attribute.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
'is_visible_on_front' => 1,
9999
'used_in_product_listing' => 1,
100100
'used_for_sort_by' => 1,
101+
'position' => 1,
101102
'frontend_label' => ['Second Test Configurable'],
102103
'backend_type' => 'int',
103104
'option' => [

0 commit comments

Comments
 (0)