diff --git a/src/GraphQL/FieldHelper/DataObjectFieldHelper.php b/src/GraphQL/FieldHelper/DataObjectFieldHelper.php index e8c5efb5..c6d0b1b2 100644 --- a/src/GraphQL/FieldHelper/DataObjectFieldHelper.php +++ b/src/GraphQL/FieldHelper/DataObjectFieldHelper.php @@ -400,8 +400,7 @@ public function doExtractData(FieldNode $ast, &$data, $container, $args, $contex // in this case we just try to get the data directly if ($container instanceof DefaultMockup) { try { - // we don't have to take care about localization because this is already handled in elastic - $data[$astName] = $container->$getter(); + $this->setValueFromMockObject($data, $container, $astName); } catch (\Exception $e) { Logger::info('Could not get data from Datahub/DataObjectFieldHelper with message: ' . $e->getMessage()); } @@ -409,6 +408,38 @@ public function doExtractData(FieldNode $ast, &$data, $container, $args, $contex } } + /** + * Try to get the data from the mock object. + * + * Elastic values are already language specific so no locale handling. + * + * Because the DefaultMockup class doesn't provide APIs to check if data + * exist we've to load all the things and essentially rebuild how + * \Pimcore\Bundle\EcommerceFrameworkBundle\Model\DefaultMockup::__call() + * works. + * + * @param $data + * @param \Pimcore\Bundle\EcommerceFrameworkBundle\Model\DefaultMockup $container + * @param $astName + * + * @return mixed|void + */ + protected function setValueFromMockObject(&$data, DefaultMockup $container, $astName) + { + $params = $container->getParams(); + if (is_array($params) && array_key_exists($astName, $params)) { + $data[$astName] = $params[$astName]; + } else { + $relations = $container->getRelations(); + if (is_array($relations) && array_key_exists($astName, $relations)) { + $relation = $container->getRelationAttribute($astName); + if ($relation) { + $data[$astName] = $relation; + } + } + } + } + /** * @param object $container * @param string $astName