From 3105ce1e8138535962c7528e4e2e414d698e117c Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 2 Jun 2021 12:50:42 +0200 Subject: [PATCH] fixed product lits bad variations language --- .../MaterioSchemaExtension.php | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php b/web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php index 77fe5f93..f6aed7ed 100644 --- a/web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php +++ b/web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php @@ -1354,11 +1354,36 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase { ->map('path', $builder->fromValue('field_price_description.value')) ); + // TODO: match the right language $registry->addFieldResolver('Product', 'variations', - $builder->produce('entity_reference') - ->map('entity', $builder->fromParent()) - ->map('field', $builder->fromValue('variations')) - ); + // $builder->produce('entity_reference') + // ->map('entity', $builder->fromParent()) + // ->map('field', $builder->fromValue('variations')) + $builder->compose( + $builder->callback(function($parent, $args){ + $variations = $parent->get('variations')->getValue(); + $ids = []; + foreach ($variations as $key => $value) { + $ids[] = $value['target_id']; + } + $lang = $parent->language()->getId(); + return [ + "ids" => $ids, + "language" => $lang + ]; + }), + $builder->produce('entity_load_multiple') + ->map('type', $builder->fromValue('commerce_product_variation')) + // ->map('bundles', $builder->fromValue(['materiau'])) + ->map('ids', $builder->callback(function($parent, $args){ + return $parent['ids']; + })) + ->map('language', $builder->callback(function($parent, $args){ + return $parent['language']; + })) + ) + ); + } protected function addVariation(ResolverRegistryInterface $registry, ResolverBuilder $builder) {