Skip to content

Commit

Permalink
Mutation (input)QuantityValue - Adding the option to enter units via …
Browse files Browse the repository at this point in the history
…UnitID (#835)

* Update InputQuantityValueInputType.php

* Update QuantityValueInputType.php

* Update InputQuantityValue.php

* Update QuantityValue.php
  • Loading branch information
leitge authored Mar 12, 2024
1 parent 5456da0 commit ca67bfe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info)
$attribute = $this->getAttribute();
Service::setValue($object, $attribute, function ($container, $setter) use ($newValue) {
if ($newValue) {
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']);
$unit = null;
if (isset($newValue['unitId'])) {
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getById($newValue['unitId']);
} elseif (isset($newValue['unit'])) {
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']);
}
$inputQuantityValue = new \Pimcore\Model\DataObject\Data\InputQuantityValue($newValue['value'], $unit);

return $container->$setter($inputQuantityValue);
Expand Down
7 changes: 6 additions & 1 deletion src/GraphQL/DataObjectInputProcessor/QuantityValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info)
$attribute = $this->getAttribute();
Service::setValue($object, $attribute, function ($container, $setter) use ($newValue) {
if ($newValue) {
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']);
$unit = null;
if (isset($newValue['unitId'])) {
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getById($newValue['unitId']);
} elseif (isset($newValue['unit'])) {
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']);
}
$quantityValue = new \Pimcore\Model\DataObject\Data\QuantityValue($newValue['value'], $unit);

return $container->$setter($quantityValue);
Expand Down
1 change: 1 addition & 0 deletions src/GraphQL/DataObjectType/InputQuantityValueInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function build(&$config)
$config['fields'] = [
'value' => Type::string(),
'unit' => Type::string(),
'unitId' => Type::string()
];
}
}
1 change: 1 addition & 0 deletions src/GraphQL/DataObjectType/QuantityValueInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function build(&$config)
$config['fields'] = [
'value' => Type::float(),
'unit' => Type::string(),
'unitId' => Type::string()
];
}
}

0 comments on commit ca67bfe

Please sign in to comment.