Преглед на файлове

fixed product lits bad variations language

bach преди 3 години
родител
ревизия
3105ce1e81
променени са 1 файла, в които са добавени 29 реда и са изтрити 4 реда
  1. 29 4
      web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php

+ 29 - 4
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) {