Skip to content

Commit fed68e8

Browse files
authored
ENGCOM-5496: customizable_options.values contains everything but value(s) #712
2 parents dcba65a + 9d902f2 commit fed68e8

File tree

6 files changed

+98
-10
lines changed

6 files changed

+98
-10
lines changed

app/code/Magento/QuoteGraphQl/Model/CartItem/DataProvider/CustomizableOptionValue/Multiple.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getData(
5454
$selectedOptionValueData[] = [
5555
'id' => $selectedOption->getId(),
5656
'label' => $optionValue->getTitle(),
57+
'value' => $optionId,
5758
'price' => [
5859
'type' => strtoupper($optionValue->getPriceType()),
5960
'units' => $priceValueUnits,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ type SelectedCustomizableOption {
327327
type SelectedCustomizableOptionValue {
328328
id: Int!
329329
label: String!
330-
value: String
330+
value: String!
331331
price: CartItemSelectedOptionValuePrice!
332332
}
333333

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ public function testAddSimpleProductWithOptions()
6464
$customizableOptionsOutput = $response['addSimpleProductsToCart']['cart']['items'][0]['customizable_options'];
6565
$assignedOptionsCount = count($customOptionsValues);
6666
for ($counter = 0; $counter < $assignedOptionsCount; $counter++) {
67+
$expectedValues = $this->buildExpectedValuesArray($customOptionsValues[$counter]['value_string']);
6768
self::assertEquals(
68-
$customOptionsValues[$counter]['value_string'],
69-
$customizableOptionsOutput[$counter]['values'][0]['value']
69+
$expectedValues,
70+
$customizableOptionsOutput[$counter]['values']
7071
);
7172
}
7273
}
@@ -150,18 +151,38 @@ private function getCustomOptionsValuesForQuery(string $sku): array
150151
$optionType = $customOption->getType();
151152
if ($optionType == 'field' || $optionType == 'area') {
152153
$customOptionsValues[] = [
153-
'id' => (int) $customOption->getOptionId(),
154+
'id' => (int)$customOption->getOptionId(),
154155
'value_string' => 'test'
155156
];
156157
} elseif ($optionType == 'drop_down') {
157158
$optionSelectValues = $customOption->getValues();
158159
$customOptionsValues[] = [
159-
'id' => (int) $customOption->getOptionId(),
160+
'id' => (int)$customOption->getOptionId(),
160161
'value_string' => reset($optionSelectValues)->getOptionTypeId()
161162
];
163+
} elseif ($optionType == 'multiple') {
164+
$customOptionsValues[] = [
165+
'id' => (int)$customOption->getOptionId(),
166+
'value_string' => '[' . implode(',', array_keys($customOption->getValues())) . ']'
167+
];
162168
}
163169
}
164-
165170
return $customOptionsValues;
166171
}
172+
173+
/**
174+
* Build the part of expected response.
175+
*
176+
* @param string $assignedValue
177+
* @return array
178+
*/
179+
private function buildExpectedValuesArray(string $assignedValue) : array
180+
{
181+
$assignedOptionsArray = explode(',', trim($assignedValue, '[]'));
182+
$expectedArray = [];
183+
foreach ($assignedOptionsArray as $assignedOption) {
184+
$expectedArray[] = ['value' => $assignedOption];
185+
}
186+
return $expectedArray;
187+
}
167188
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ public function testAddVirtualProductWithOptions()
6464
$customizableOptionsOutput = $response['addVirtualProductsToCart']['cart']['items'][0]['customizable_options'];
6565
$assignedOptionsCount = count($customOptionsValues);
6666
for ($counter = 0; $counter < $assignedOptionsCount; $counter++) {
67+
$expectedValues = $this->buildExpectedValuesArray($customOptionsValues[$counter]['value_string']);
6768
self::assertEquals(
68-
$customOptionsValues[$counter]['value_string'],
69-
$customizableOptionsOutput[$counter]['values'][0]['value']
69+
$expectedValues,
70+
$customizableOptionsOutput[$counter]['values']
7071
);
7172
}
7273
}
@@ -150,18 +151,39 @@ private function getCustomOptionsValuesForQuery(string $sku): array
150151
$optionType = $customOption->getType();
151152
if ($optionType == 'field' || $optionType == 'area') {
152153
$customOptionsValues[] = [
153-
'id' => (int) $customOption->getOptionId(),
154+
'id' => (int)$customOption->getOptionId(),
154155
'value_string' => 'test'
155156
];
156157
} elseif ($optionType == 'drop_down') {
157158
$optionSelectValues = $customOption->getValues();
158159
$customOptionsValues[] = [
159-
'id' => (int) $customOption->getOptionId(),
160+
'id' => (int)$customOption->getOptionId(),
160161
'value_string' => reset($optionSelectValues)->getOptionTypeId()
161162
];
163+
} elseif ($optionType == 'multiple') {
164+
$customOptionsValues[] = [
165+
'id' => (int)$customOption->getOptionId(),
166+
'value_string' => '[' . implode(',', array_keys($customOption->getValues())) . ']'
167+
];
162168
}
163169
}
164170

165171
return $customOptionsValues;
166172
}
173+
174+
/**
175+
* Build the part of expected response.
176+
*
177+
* @param string $assignedValue
178+
* @return array
179+
*/
180+
private function buildExpectedValuesArray(string $assignedValue) : array
181+
{
182+
$assignedOptionsArray = explode(',', trim($assignedValue, '[]'));
183+
$expectedArray = [];
184+
foreach ($assignedOptionsArray as $assignedOption) {
185+
$expectedArray[] = ['value' => $assignedOption];
186+
}
187+
return $expectedArray;
188+
}
167189
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@
8484
'sort_order' => 2,
8585
],
8686
],
87+
],
88+
[
89+
'title' => 'multiple option',
90+
'type' => 'multiple',
91+
'is_require' => false,
92+
'sort_order' => 5,
93+
'values' => [
94+
[
95+
'title' => 'multiple option 1',
96+
'price' => 10,
97+
'price_type' => 'fixed',
98+
'sku' => 'multiple option 1 sku',
99+
'sort_order' => 1,
100+
],
101+
[
102+
'title' => 'multiple option 2',
103+
'price' => 20,
104+
'price_type' => 'fixed',
105+
'sku' => 'multiple option 2 sku',
106+
'sort_order' => 2,
107+
],
108+
],
87109
]
88110
];
89111

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@
8484
'sort_order' => 2,
8585
],
8686
],
87+
],
88+
[
89+
'title' => 'multiple option',
90+
'type' => 'multiple',
91+
'is_require' => false,
92+
'sort_order' => 5,
93+
'values' => [
94+
[
95+
'title' => 'multiple option 1',
96+
'price' => 10,
97+
'price_type' => 'fixed',
98+
'sku' => 'multiple option 1 sku',
99+
'sort_order' => 1,
100+
],
101+
[
102+
'title' => 'multiple option 2',
103+
'price' => 20,
104+
'price_type' => 'fixed',
105+
'sku' => 'multiple option 2 sku',
106+
'sort_order' => 2,
107+
],
108+
],
87109
]
88110
];
89111

0 commit comments

Comments
 (0)