Skip to content

Commit 84a808e

Browse files
authored
Merge pull request #5385 from magento-honey-badgers/honey-235-bug-pr
[honey] Honey Badgers 2.3.5 bugfixes
2 parents ff93d50 + 2fbe611 commit 84a808e

File tree

9 files changed

+305
-295
lines changed

9 files changed

+305
-295
lines changed

app/code/Magento/CatalogGraphQl/Model/Config/FilterAttributeReader.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
use Magento\Framework\Config\ReaderInterface;
1111
use Magento\Framework\GraphQl\Schema\Type\Entity\MapperInterface;
1212
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
13-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection;
1413
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1514

1615
/**
1716
* Adds custom/eav attributes to product filter type in the GraphQL config.
1817
*
1918
* Product Attribute should satisfy the following criteria:
20-
* - Attribute is searchable
21-
* - "Visible in Advanced Search" is set to "Yes"
22-
* - Attribute of type "Select" must have options
19+
* - (Attribute is searchable AND "Visible in Advanced Search" is set to "Yes")
20+
* - OR attribute is "Used in Layered Navigation"
21+
* - AND Attribute of type "Select" must have options
2322
*/
2423
class FilterAttributeReader implements ReaderInterface
2524
{
@@ -77,7 +76,7 @@ public function read($scope = null) : array
7776
$typeNames = $this->mapper->getMappedTypes(self::ENTITY_TYPE);
7877
$config = [];
7978

80-
foreach ($this->getAttributeCollection() as $attribute) {
79+
foreach ($this->getFilterAttributes() as $attribute) {
8180
$attributeCode = $attribute->getAttributeCode();
8281

8382
foreach ($typeNames as $typeName) {
@@ -120,15 +119,25 @@ private function getFilterType(Attribute $attribute): string
120119
}
121120

122121
/**
123-
* Create attribute collection
122+
* Get attributes to use in product filter input
124123
*
125-
* @return Collection|\Magento\Catalog\Model\ResourceModel\Eav\Attribute[]
124+
* @return array
126125
*/
127-
private function getAttributeCollection()
126+
private function getFilterAttributes(): array
128127
{
129-
return $this->collectionFactory->create()
128+
$filterableAttributes = $this->collectionFactory
129+
->create()
130+
->addHasOptionsFilter()
131+
->addIsFilterableFilter()
132+
->getItems();
133+
134+
$searchableAttributes = $this->collectionFactory
135+
->create()
130136
->addHasOptionsFilter()
131137
->addIsSearchableFilter()
132-
->addDisplayInAdvancedSearchFilter();
138+
->addDisplayInAdvancedSearchFilter()
139+
->getItems();
140+
141+
return $filterableAttributes + $searchableAttributes;
133142
}
134143
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/FilterArgument/ProductEntityAttributesForAst.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
*/
1818
class ProductEntityAttributesForAst implements FieldEntityAttributesInterface
1919
{
20+
private const PRODUCT_BASE_TYPE = 'SimpleProduct';
21+
22+
private const PRODUCT_FILTER_INPUT = 'ProductAttributeFilterInput';
23+
2024
/**
2125
* @var ConfigInterface
2226
*/
@@ -51,9 +55,9 @@ public function __construct(
5155
*/
5256
public function getEntityAttributes() : array
5357
{
54-
$productTypeSchema = $this->config->getConfigElement('SimpleProduct');
58+
$productTypeSchema = $this->config->getConfigElement(self::PRODUCT_BASE_TYPE);
5559
if (!$productTypeSchema instanceof Type) {
56-
throw new \LogicException(__("SimpleProduct type not defined in schema."));
60+
throw new \LogicException(__(self::PRODUCT_BASE_TYPE . " type not defined in schema."));
5761
}
5862

5963
$fields = [];
@@ -69,6 +73,9 @@ public function getEntityAttributes() : array
6973
}
7074
}
7175

76+
$productAttributeFilterFields = $this->getProductAttributeFilterFields();
77+
$fields = array_merge($fields, $productAttributeFilterFields);
78+
7279
foreach ($this->additionalAttributes as $attributeName) {
7380
$fields[$attributeName] = [
7481
'type' => 'String',
@@ -78,4 +85,24 @@ public function getEntityAttributes() : array
7885

7986
return $fields;
8087
}
88+
89+
/**
90+
* Get fields from ProductAttributeFilterInput
91+
*
92+
* @return array
93+
*/
94+
private function getProductAttributeFilterFields()
95+
{
96+
$filterFields = [];
97+
98+
$productAttributeFilterSchema = $this->config->getConfigElement(self::PRODUCT_FILTER_INPUT);
99+
$productAttributeFilterFields = $productAttributeFilterSchema->getFields();
100+
foreach ($productAttributeFilterFields as $filterField) {
101+
$filterFields[$filterField->getName()] = [
102+
'type' => 'String',
103+
'fieldName' => $filterField->getName(),
104+
];
105+
}
106+
return $filterFields;
107+
}
81108
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,17 @@ type CustomizableFileValue @doc(description: "CustomizableFileValue defines the
199199
interface MediaGalleryInterface @doc(description: "Contains basic information about a product image or video.") @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\MediaGalleryTypeResolver") {
200200
url: String @doc(description: "The URL of the product image or video.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGallery\\Url")
201201
label: String @doc(description: "The label of the product image or video.")
202+
position: Int @doc(description: "The media item's position after it has been sorted.")
203+
disabled: Boolean @doc(description: "Whether the image is hidden from view.")
202204
}
203205

204206
type ProductImage implements MediaGalleryInterface @doc(description: "Product image information. Contains the image URL and label.") {
205207
}
206208

209+
type ProductVideo implements MediaGalleryInterface @doc(description: "Contains information about a product video.") {
210+
video_content: ProductMediaGalleryEntriesVideoContent @doc(description: "Contains a ProductMediaGalleryEntriesVideoContent object.")
211+
}
212+
207213
interface CustomizableOptionInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\CustomizableOptionTypeResolver") @doc(description: "The CustomizableOptionInterface contains basic information about a customizable option. It can be implemented by several types of configurable options.") {
208214
title: String @doc(description: "The display name for this option.")
209215
required: Boolean @doc(description: "Indicates whether the option is required.")
@@ -403,7 +409,7 @@ type MediaGalleryEntry @doc(description: "MediaGalleryEntry defines characterist
403409
media_type: String @doc(description: "image or video.")
404410
label: String @doc(description: "The alt text displayed on the UI when the user points to the image.")
405411
position: Int @doc(description: "The media item's position after it has been sorted.")
406-
disabled: Boolean @doc(description: "Whether the image is hidden from vie.")
412+
disabled: Boolean @doc(description: "Whether the image is hidden from view.")
407413
types: [String] @doc(description: "Array of image types. It can have the following values: image, small_image, thumbnail.")
408414
file: String @doc(description: "The path of the image on the server.")
409415
content: ProductMediaGalleryEntriesContent @doc(description: "Contains a ProductMediaGalleryEntriesContent object.")
@@ -466,7 +472,3 @@ type StoreConfig @doc(description: "The type contains information about a store
466472
catalog_default_sort_by : String @doc(description: "Default Sort By.")
467473
root_category_id: Int @doc(description: "The ID of the root category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\RootCategoryId")
468474
}
469-
470-
type ProductVideo @doc(description: "Contains information about a product video.") implements MediaGalleryInterface {
471-
video_content: ProductMediaGalleryEntriesVideoContent @doc(description: "Contains a ProductMediaGalleryEntriesVideoContent object.")
472-
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
*/
1515
class MediaGalleryTest extends GraphQlAbstract
1616
{
17-
/**
18-
* @var \Magento\TestFramework\ObjectManager
19-
*/
20-
private $objectManager;
21-
22-
protected function setUp()
23-
{
24-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
25-
}
26-
2717
/**
2818
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php
2919
*/
@@ -38,7 +28,7 @@ public function testProductSmallImageUrlWithExistingImage()
3828
url
3929
}
4030
}
41-
}
31+
}
4232
}
4333
QUERY;
4434
$response = $this->graphQlQuery($query);
@@ -57,15 +47,15 @@ public function testMediaGalleryTypesAreCorrect()
5747
$query = <<<QUERY
5848
{
5949
products(filter: {sku: {eq: "{$productSku}"}}) {
60-
items {
50+
items {
6151
media_gallery_entries {
6252
label
6353
media_type
6454
file
6555
types
6656
}
6757
}
68-
}
58+
}
6959
}
7060
QUERY;
7161
$response = $this->graphQlQuery($query);
@@ -91,23 +81,29 @@ public function testMediaGallery()
9181
$query = <<<QUERY
9282
{
9383
products(filter: {sku: {eq: "{$productSku}"}}) {
94-
items {
84+
items {
9585
media_gallery {
9686
label
9787
url
88+
position
89+
disabled
9890
}
9991
}
100-
}
92+
}
10193
}
10294
QUERY;
10395
$response = $this->graphQlQuery($query);
10496
$this->assertNotEmpty($response['products']['items'][0]['media_gallery']);
10597
$mediaGallery = $response['products']['items'][0]['media_gallery'];
10698
$this->assertCount(2, $mediaGallery);
10799
$this->assertEquals('Image Alt Text', $mediaGallery[0]['label']);
108-
self::assertTrue($this->checkImageExists($mediaGallery[0]['url']));
100+
$this->assertEquals(1, $mediaGallery[0]['position']);
101+
$this->assertFalse($mediaGallery[0]['disabled']);
102+
$this->assertTrue($this->checkImageExists($mediaGallery[0]['url']));
109103
$this->assertEquals('Thumbnail Image', $mediaGallery[1]['label']);
110-
self::assertTrue($this->checkImageExists($mediaGallery[1]['url']));
104+
$this->assertEquals(2, $mediaGallery[1]['position']);
105+
$this->assertFalse($mediaGallery[1]['disabled']);
106+
$this->assertTrue($this->checkImageExists($mediaGallery[1]['url']));
111107
}
112108

113109
/**
@@ -119,10 +115,12 @@ public function testMediaGalleryForProductVideos()
119115
$query = <<<QUERY
120116
{
121117
products(filter: {sku: {eq: "{$productSku}"}}) {
122-
items {
118+
items {
123119
media_gallery {
124120
label
125121
url
122+
position
123+
disabled
126124
... on ProductVideo {
127125
video_content {
128126
media_type
@@ -135,15 +133,17 @@ public function testMediaGalleryForProductVideos()
135133
}
136134
}
137135
}
138-
}
136+
}
139137
}
140138
QUERY;
141139
$response = $this->graphQlQuery($query);
142140
$this->assertNotEmpty($response['products']['items'][0]['media_gallery']);
143141
$mediaGallery = $response['products']['items'][0]['media_gallery'];
144142
$this->assertCount(1, $mediaGallery);
145143
$this->assertEquals('Video Label', $mediaGallery[0]['label']);
146-
self::assertTrue($this->checkImageExists($mediaGallery[0]['url']));
144+
$this->assertTrue($this->checkImageExists($mediaGallery[0]['url']));
145+
$this->assertFalse($mediaGallery[0]['disabled']);
146+
$this->assertEquals(2, $mediaGallery[0]['position']);
147147
$this->assertNotEmpty($mediaGallery[0]['video_content']);
148148
$video_content = $mediaGallery[0]['video_content'];
149149
$this->assertEquals('external-video', $video_content['media_type']);

0 commit comments

Comments
 (0)