Skip to content

Commit ea24381

Browse files
author
Prabhu Ram
committed
MC-38443: [GraphQl] media_gallery has redundant entries in configurable_options_selection_metadata
- Fixed redundant entries and updated query name
1 parent 057c268 commit ea24381

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/OptionsSelectionMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4040
throw new LocalizedException(__('"model" value should be specified'));
4141
}
4242

43-
$selectedOptions = $args['selectedConfigurableOptionValues'] ?? [];
43+
$selectedOptions = $args['configurableOptionValueUids'] ?? [];
4444
/** @var ProductInterface $product */
4545
$product = $value['model'];
4646

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/SelectionMediaGallery.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
3030
foreach ($usedProducts as $usedProduct) {
3131
if (in_array($usedProduct->getId(), $availableSelectionProducts)) {
3232
foreach ($usedProduct->getMediaGalleryEntries() ?? [] as $key => $entry) {
33-
$index = $usedProduct->getId() . '_' . $key;
34-
$mediaGalleryEntries[$index] = $entry->getData();
33+
$entryData = $entry->getData();
34+
$initialIndex = $usedProduct->getId() . '_' . $key;
35+
$index = $this->prepareIndex($entryData, $initialIndex);
36+
$mediaGalleryEntries[$index] = $entryData;
3537
$mediaGalleryEntries[$index]['model'] = $usedProduct;
3638
if ($entry->getExtensionAttributes() && $entry->getExtensionAttributes()->getVideoContent()) {
3739
$mediaGalleryEntries[$index]['video_content']
@@ -42,4 +44,26 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4244
}
4345
return $mediaGalleryEntries;
4446
}
47+
48+
/**
49+
* Formulate an index to have unique set of media entries
50+
*
51+
* @param array $entryData
52+
* @param string $initialIndex
53+
* @return string
54+
*/
55+
private function prepareIndex(array $entryData, string $initialIndex) : string
56+
{
57+
$index = $initialIndex;
58+
if (isset($entryData['media_type'])) {
59+
$index = $entryData['media_type'];
60+
}
61+
if (isset($entryData['file'])) {
62+
$index = $index.'_'.$entryData['file'];
63+
}
64+
if (isset($entryData['position'])) {
65+
$index = $index.'_'.$entryData['position'];
66+
}
67+
return $index;
68+
}
4569
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Mutation {
77
type ConfigurableProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "ConfigurableProduct defines basic features of a configurable product and its simple product variants") {
88
variants: [ConfigurableVariant] @doc(description: "An array of variants of products") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ConfigurableVariant")
99
configurable_options: [ConfigurableProductOptions] @doc(description: "An array of linked simple product items") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\Options")
10-
configurable_options_selection_metadata(selectedConfigurableOptionValues: [ID!]): ConfigurableOptionsSelectionMetadata @doc(description: "Metadata for the specified configurable options selection") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\OptionsSelectionMetadata")
10+
configurable_product_options_selection(configurableOptionValueUids: [ID!]): ConfigurableProductOptionsSelection @doc(description: "Metadata for the specified configurable options selection") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\OptionsSelectionMetadata")
1111
}
1212

1313
type ConfigurableVariant @doc(description: "An array containing all the simple product variants of a configurable product") {
@@ -80,7 +80,7 @@ type ConfigurableWishlistItem implements WishlistItemInterface @doc(description:
8080
configurable_options: [SelectedConfigurableOption!] @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ConfigurableOptions") @doc (description: "An array of selected configurable options")
8181
}
8282

83-
type ConfigurableOptionsSelectionMetadata @doc(description: "Metadata corresponding to the configurable options selection.") {
83+
type ConfigurableProductOptionsSelection @doc(description: "Metadata corresponding to the configurable options selection.") {
8484
options_available_for_selection: [ConfigurableOptionAvailableForSelection!] @doc(description: "Configurable options available for further selection based on current selection.")
8585
media_gallery: [MediaGalleryInterface!] @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\SelectionMediaGallery") @doc(description: "Product images and videos corresponding to the specified configurable options selection.")
8686
variant: SimpleProduct @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\Variant\\Variant") @doc(description: "Variant represented by the specified configurable options selection. It is expected to be null, until selections are made for each configurable option.")

0 commit comments

Comments
 (0)