$value ) { $term = \get_term_by( 'slug', $value, $name ); if ( empty( $term ) ) { $attributes[] = array( // ID create for caching only, not object retrieval. 'id' => base64_encode( $parent_id . '||' . $name . '||' . $value ), 'attributeId' => 0, 'name' => $name, 'value' => $value, ); } else { $attributes[] = array( // ID create for caching only, not object retrieval. 'id' => base64_encode( $parent_id . '||' . $name . '||' . $value ), 'attributeId' => $term->term_id, 'name' => $term->taxonomy, 'value' => $term->name, ); } } } return $attributes; } /** * Creates connection * * @param mixed $source - Connection source Model instance. * @param array $args - Connection arguments. * @param AppContext $context - AppContext object. * @param ResolveInfo $info - ResolveInfo object. */ public function resolve( $source, array $args, AppContext $context, ResolveInfo $info ) { if ( is_a( $source, Product::class ) ) { $attributes = $this->to_data_array( $source->default_attributes, $source->ID ); } else { $attributes = $this->to_data_array( $source->attributes, $source->ID ); } $connection = Relay::connectionFromArray( $attributes, $args ); $nodes = array(); if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; } } $connection['nodes'] = ! empty( $nodes ) ? $nodes : null; return ! empty( $attributes ) ? $connection : null; } }