@@ -21,15 +21,9 @@ class Products {
2121 public static function register_connections () {
2222 // From RootQuery.
2323 register_graphql_connection ( self ::get_connection_config () );
24+
2425 // From Coupon.
25- register_graphql_connection (
26- self ::get_connection_config (
27- array (
28- 'fromType ' => 'Coupon ' ,
29- 'fromFieldName ' => 'products ' ,
30- )
31- )
32- );
26+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'Coupon ' ) ) );
3327 register_graphql_connection (
3428 self ::get_connection_config (
3529 array (
@@ -38,7 +32,8 @@ public static function register_connections() {
3832 )
3933 )
4034 );
41- // From Product.
35+
36+ // Connections from all product types to related and upsell.
4237 register_graphql_connection (
4338 self ::get_connection_config (
4439 array (
@@ -55,63 +50,71 @@ public static function register_connections() {
5550 )
5651 )
5752 );
53+
54+ $ product_types = array_values ( \WP_GraphQL_WooCommerce::get_enabled_product_types () );
55+ foreach ( $ product_types as $ product_type ) {
56+ register_graphql_connection (
57+ self ::get_connection_config (
58+ array (
59+ 'fromType ' => $ product_type ,
60+ 'fromFieldName ' => 'related ' ,
61+ )
62+ )
63+ );
64+ register_graphql_connection (
65+ self ::get_connection_config (
66+ array (
67+ 'fromType ' => $ product_type ,
68+ 'fromFieldName ' => 'upsell ' ,
69+ )
70+ )
71+ );
72+ }
73+
74+ // Group product children connection.
75+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'GroupProduct ' ) ) );
76+
77+ // Product cross-sell connections.
5878 register_graphql_connection (
5979 self ::get_connection_config (
6080 array (
61- 'fromType ' => 'Product ' ,
81+ 'fromType ' => 'SimpleProduct ' ,
6282 'fromFieldName ' => 'crossSell ' ,
6383 )
6484 )
6585 );
6686 register_graphql_connection (
6787 self ::get_connection_config (
6888 array (
69- 'fromType ' => 'Product ' ,
70- 'fromFieldName ' => 'grouped ' ,
89+ 'fromType ' => 'VariableProduct ' ,
90+ 'fromFieldName ' => 'crossSell ' ,
7191 )
7292 )
7393 );
7494
75- // From Product to ProductVariation.
95+ // From VariableProduct to ProductVariation.
7696 register_graphql_connection (
7797 self ::get_connection_config (
7898 array (
79- 'fromType ' => 'Product ' ,
99+ 'fromType ' => 'VariableProduct ' ,
80100 'toType ' => 'ProductVariation ' ,
81101 'fromFieldName ' => 'variations ' ,
82102 )
83103 )
84104 );
85105
86106 // From ProductCategory.
87- register_graphql_connection (
88- self ::get_connection_config (
89- array (
90- 'fromType ' => 'ProductCategory ' ,
91- 'fromFieldName ' => 'products ' ,
92- )
93- )
94- );
107+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'ProductCategory ' ) ) );
95108
96109 // From ProductTag.
97- register_graphql_connection (
98- self ::get_connection_config (
99- array (
100- 'fromType ' => 'ProductTag ' ,
101- 'fromFieldName ' => 'products ' ,
102- )
103- )
104- );
110+ register_graphql_connection ( self ::get_connection_config ( array ( 'fromType ' => 'ProductTag ' ) ) );
105111
106112 // From WooCommerce product attributes.
107113 $ attributes = \WP_GraphQL_WooCommerce::get_product_attribute_taxonomies ();
108114 foreach ( $ attributes as $ attribute ) {
109115 register_graphql_connection (
110116 self ::get_connection_config (
111- array (
112- 'fromType ' => ucfirst ( graphql_format_field_name ( $ attribute ) ),
113- 'fromFieldName ' => 'products ' ,
114- )
117+ array ( 'fromType ' => ucfirst ( graphql_format_field_name ( $ attribute ) ) )
115118 )
116119 );
117120 register_graphql_connection (
0 commit comments