Skip to content

Commit

Permalink
Cannot return null for non-nullable field SelectedCustomizableOptionV…
Browse files Browse the repository at this point in the history
…alue.sort_order and Call to a member function getPriceType() on null
  • Loading branch information
XxXgeoXxX authored and naydav committed Apr 30, 2019
1 parent 93a8162 commit 81daba8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Quote\Model\Quote;
use phpDocumentor\Reflection\Types\Mixed_;

/**
* Add simple product to cart
Expand Down Expand Up @@ -140,7 +141,9 @@ private function extractCustomizableOptions(array $cartItemData): array

$customizableOptionsData = [];
foreach ($customizableOptions as $customizableOption) {
$customizableOptionsData[$customizableOption['id']] = $customizableOption['value'];
$customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptions(
$customizableOption['value']
);
}
return $customizableOptionsData;
}
Expand All @@ -161,4 +164,17 @@ private function createBuyRequest(float $quantity, array $customOptions): DataOb
],
]);
}

/**
* @param string $value
* @return string|array
*/
private function convertCustomOptions(string $value)
{
if (substr($value, 0, 1) === "[" ||
substr($value, strlen($value) - 1, 1) === "]") {
return explode(',', substr($value, 1, -1));
}
return $value;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<item name="area" xsi:type="string">Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Text</item>
<item name="drop_down" xsi:type="string">Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Dropdown</item>
<item name="radio" xsi:type="string">Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Dropdown</item>
<item name="checkbox" xsi:type="string">Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Dropdown</item>
<item name="checkbox" xsi:type="string">Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Multiple</item>
<item name="multiple" xsi:type="string">Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Multiple</item>
</argument>
</arguments>
Expand Down

0 comments on commit 81daba8

Please sign in to comment.