Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
#141 Implemented different strategies of filling graphql output type …
Browse files Browse the repository at this point in the history
…in case of different option types
  • Loading branch information
Roman Glushko committed Sep 4, 2018
1 parent e9ae719 commit 1012b3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$customOptionIds = explode(',', $optionIds->getValue());

foreach ($customOptionIds as $optionId) {
$customOptionData = $this->getOptionData($cartItem, $optionId);
$customOptionData = $this->getOptionData($cartItem, (int) $optionId);

if (count($customOptionData) > 0) {
if (0 === count($customOptionData)) {
continue;
}

Expand Down Expand Up @@ -110,6 +110,7 @@ private function getOptionData($cartItem, int $optionId): array

if ('file' == $option->getType()) {
$downloadParams = $cartItem->getFileDownloadParams();

if ($downloadParams) {
$url = $downloadParams->getUrl();
if ($url) {
Expand All @@ -122,24 +123,33 @@ private function getOptionData($cartItem, int $optionId): array
}
}

$optionValue = $option->getValueById($itemOption->getValue());

$selectedOptionValueData = [
'id' => $itemOption->getId(),
'label' => $optionTypeGroup->getFormattedOptionValue($itemOption->getValue()),
];

if ('drop_down' == $option->getType()) {
$optionValue = $option->getValueById($itemOption->getValue());
$selectedOptionValueData['price'] = [
'type' => strtoupper($optionValue->getPriceType()),
'units' => '$',
'value' => $optionValue->getPrice(),
];
}

if ('field' == $option->getType()) {
$selectedOptionValueData['price'] = [
'type' => strtoupper($option->getPriceType()),
'units' => '$',
'value' => $option->getPrice(),
];
}

return [
'id' => $option->getId(),
'label' => $option->getTitle(),
'type' => $option->getType(),
'values' => [
[
'id' => $optionValue->getId(),
'label' => $optionValue->getTitle(),
'sort_order' => $optionValue->getSortOrder(),
'price' => [
'type' => strtoupper($optionValue->getPriceType()),
'units' => '$',
'value' => $optionValue->getPrice(),
]
]
],
'values' => [$selectedOptionValueData],
'sort_order' => $option->getSortOrder(),
];
}
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type SelectedCustomizableOptionValue {
id: Int
label: String!
price: CartItemSelectedOptionValuePrice!
sort_order: Int!
}

type CartItemSelectedOptionValuePrice {
Expand Down

0 comments on commit 1012b3c

Please sign in to comment.