Skip to content

Commit 0809b69

Browse files
committed
magento/graphql-ce#761: [Customizable Options] Call to a member function format() on boolean
1 parent 10d20bf commit 0809b69

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

app/code/Magento/CatalogGraphQl/Model/Product/Option/DateType.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1414

1515
/**
16-
* CatalogGraphQl product option date type.
17-
*
18-
* @author Magento Core Team <core@magentocommerce.com>
19-
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
16+
* CatalogGraphQl product option date type
2017
*/
2118
class DateType extends ProductDateOptionType
2219
{

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public function testAddSimpleProductWithOptions()
5757

5858
$customOptionsValues = $this->getCustomOptionsValuesForQueryBySku->execute($sku);
5959
/* Generate customizable options fragment for GraphQl request */
60-
$queryCustomizableOptionValues = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode(array_values($customOptionsValues)));
60+
$queryCustomizableOptionValues = preg_replace(
61+
'/"([^"]+)"\s*:\s*/', '$1:',
62+
json_encode(array_values($customOptionsValues))
63+
);
6164

6265
$customizableOptions = "customizable_options: {$queryCustomizableOptionValues}";
6366
$query = $this->getQuery($maskedQuoteId, $sku, $quantity, $customizableOptions);
@@ -114,7 +117,10 @@ public function testAddSimpleProductWithWrongDateOptionFormat()
114117

115118
$customOptionsValues = $this->getCustomOptionsValuesForQueryBySku->execute($sku);
116119
$customOptionsValues['date']['value_string'] = '12-12-12';
117-
$queryCustomizableOptionValues = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode(array_values($customOptionsValues)));
120+
$queryCustomizableOptionValues = preg_replace(
121+
'/"([^"]+)"\s*:\s*/', '$1:',
122+
json_encode(array_values($customOptionsValues))
123+
);
118124
$customizableOptions = "customizable_options: {$queryCustomizableOptionValues}";
119125
$query = $this->getQuery($maskedQuoteId, $sku, $quantity, $customizableOptions);
120126

@@ -174,7 +180,7 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity, s
174180
*/
175181
private function buildExpectedValuesArray(string $assignedValue, string $type) : array
176182
{
177-
if ($type === 'date'){
183+
if ($type === 'date') {
178184
return [['value' => date('M d, Y', strtotime($assignedValue))]];
179185
}
180186
$assignedOptionsArray = explode(',', trim($assignedValue, '[]'));

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

+18-23
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,26 @@ public function execute(string $sku): array
4040

4141
foreach ($customOptions as $customOption) {
4242
$optionType = $customOption->getType();
43-
if ($optionType == 'date') {
44-
$customOptionsValues[$optionType] = [
45-
'id' => (int)$customOption->getOptionId(),
46-
'value_string' => '2012-12-12 00:00:00',
47-
];
48-
} elseif ($optionType == 'field' || $optionType == 'area') {
49-
$customOptionsValues[$optionType] = [
50-
'id' => (int)$customOption->getOptionId(),
51-
'value_string' => 'test',
52-
];
53-
} elseif ($optionType == 'drop_down') {
54-
$optionSelectValues = $customOption->getValues();
55-
$customOptionsValues[$optionType] = [
56-
'id' => (int)$customOption->getOptionId(),
57-
'value_string' => reset($optionSelectValues)->getOptionTypeId(),
58-
];
59-
} elseif ($optionType == 'multiple') {
60-
$customOptionsValues[$optionType] = [
61-
'id' => (int)$customOption->getOptionId(),
62-
'value_string' => '[' . implode(',', array_keys($customOption->getValues())) . ']',
63-
64-
];
43+
$customOptionsValues[$optionType]['id'] = (int)$customOption->getOptionId();
44+
switch ($optionType) {
45+
case 'date':
46+
$customOptionsValues[$optionType]['value_string'] = '2012-12-12 00:00:00';
47+
break;
48+
case 'field':
49+
case 'area':
50+
$customOptionsValues[$optionType]['value_string'] = 'test';
51+
break;
52+
case 'drop_down':
53+
$optionSelectValues = $customOption->getValues();
54+
$customOptionsValues[$optionType]['value_string'] =
55+
reset($optionSelectValues)->getOptionTypeId();
56+
break;
57+
case 'multiple':
58+
$customOptionsValues[$optionType]['value_string'] =
59+
'[' . implode(',', array_keys($customOption->getValues())) . ']';
60+
break;
6561
}
6662
}
67-
6863
return $customOptionsValues;
6964
}
7065
}

0 commit comments

Comments
 (0)