Skip to content

Commit

Permalink
magento/graphql-ce#761: [Customizable Options] Call to a member funct…
Browse files Browse the repository at this point in the history
…ion format() on boolean
  • Loading branch information
lenaorobei committed Oct 14, 2019
1 parent 10d20bf commit 0809b69
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlInputException;

/**
* CatalogGraphQl product option date type.
*
* @author Magento Core Team <[email protected]>
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* CatalogGraphQl product option date type
*/
class DateType extends ProductDateOptionType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public function testAddSimpleProductWithOptions()

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

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

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

Expand Down Expand Up @@ -174,7 +180,7 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity, s
*/
private function buildExpectedValuesArray(string $assignedValue, string $type) : array
{
if ($type === 'date'){
if ($type === 'date') {
return [['value' => date('M d, Y', strtotime($assignedValue))]];
}
$assignedOptionsArray = explode(',', trim($assignedValue, '[]'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,26 @@ public function execute(string $sku): array

foreach ($customOptions as $customOption) {
$optionType = $customOption->getType();
if ($optionType == 'date') {
$customOptionsValues[$optionType] = [
'id' => (int)$customOption->getOptionId(),
'value_string' => '2012-12-12 00:00:00',
];
} elseif ($optionType == 'field' || $optionType == 'area') {
$customOptionsValues[$optionType] = [
'id' => (int)$customOption->getOptionId(),
'value_string' => 'test',
];
} elseif ($optionType == 'drop_down') {
$optionSelectValues = $customOption->getValues();
$customOptionsValues[$optionType] = [
'id' => (int)$customOption->getOptionId(),
'value_string' => reset($optionSelectValues)->getOptionTypeId(),
];
} elseif ($optionType == 'multiple') {
$customOptionsValues[$optionType] = [
'id' => (int)$customOption->getOptionId(),
'value_string' => '[' . implode(',', array_keys($customOption->getValues())) . ']',

];
$customOptionsValues[$optionType]['id'] = (int)$customOption->getOptionId();
switch ($optionType) {
case 'date':
$customOptionsValues[$optionType]['value_string'] = '2012-12-12 00:00:00';
break;
case 'field':
case 'area':
$customOptionsValues[$optionType]['value_string'] = 'test';
break;
case 'drop_down':
$optionSelectValues = $customOption->getValues();
$customOptionsValues[$optionType]['value_string'] =
reset($optionSelectValues)->getOptionTypeId();
break;
case 'multiple':
$customOptionsValues[$optionType]['value_string'] =
'[' . implode(',', array_keys($customOption->getValues())) . ']';
break;
}
}

return $customOptionsValues;
}
}

0 comments on commit 0809b69

Please sign in to comment.