From 9e01c9c77f9e5084da8efa992b089cf74b05eb7e Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Wed, 17 Jul 2024 00:03:33 +0300 Subject: [PATCH 1/6] Add Product_Attributes_Connection_Orderby_Enum with MENU_ORDER --- includes/class-type-registry.php | 1 + includes/class-wp-graphql-woocommerce.php | 1 + includes/connection/class-wc-terms.php | 9 ++- ...uct-attributes-connection-orderby-enum.php | 60 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 includes/type/enum/class-product-attributes-connection-orderby-enum.php diff --git a/includes/class-type-registry.php b/includes/class-type-registry.php index cc012515..72628eea 100644 --- a/includes/class-type-registry.php +++ b/includes/class-type-registry.php @@ -48,6 +48,7 @@ public function init() { Type\WPEnum\Currency_Enum::register(); Type\WPEnum\Shipping_Location_Type_Enum::register(); Type\WPEnum\WC_Setting_Type_Enum::register(); + Type\WPEnum\Product_Attributes_Connection_Orderby_Enum::register(); /** * InputObjects. diff --git a/includes/class-wp-graphql-woocommerce.php b/includes/class-wp-graphql-woocommerce.php index 1c9ee31c..6ae6c645 100644 --- a/includes/class-wp-graphql-woocommerce.php +++ b/includes/class-wp-graphql-woocommerce.php @@ -246,6 +246,7 @@ private function includes() { require $include_directory_path . 'type/enum/class-currency-enum.php'; require $include_directory_path . 'type/enum/class-shipping-location-type-enum.php'; require $include_directory_path . 'type/enum/class-wc-setting-type-enum.php'; + require $include_directory_path . 'type/enum/class-product-attributes-connection-orderby-enum.php'; // Include interface type class files. require $include_directory_path . 'type/interface/class-attribute.php'; diff --git a/includes/connection/class-wc-terms.php b/includes/connection/class-wc-terms.php index 71027102..4b1c46be 100644 --- a/includes/connection/class-wc-terms.php +++ b/includes/connection/class-wc-terms.php @@ -118,7 +118,14 @@ public static function register_connections() { 'toType' => 'TermNode', 'queryClass' => 'WP_Term_Query', 'fromFieldName' => 'terms', - 'connectionArgs' => self::get_connection_args(), + 'connectionArgs' => self::get_connection_args( + [ + 'orderby' => [ + 'type' => 'ProductAttributesConnectionOrderbyEnum', + 'description' => __( 'Field(s) to order terms by. Defaults to \'name\'.', 'wp-graphql-woocommerce' ), + ], + ] + ), 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { if ( ! $source->is_taxonomy() ) { throw new UserError( __( 'Invalid product attribute', 'wp-graphql-woocommerce' ) ); diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php new file mode 100644 index 00000000..28331af7 --- /dev/null +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -0,0 +1,60 @@ + __( 'Taxonomy query operators', 'wp-graphql-woocommerce' ), + 'values' => [ + 'NAME' => [ + 'value' => 'name', + 'description' => __( 'Order the connection by name.', 'wp-graphql-woocommerce' ), + ], + 'SLUG' => [ + 'value' => 'slug', + 'description' => __( 'Order the connection by slug.', 'wp-graphql-woocommerce' ), + ], + 'TERM_GROUP' => [ + 'value' => 'term_group', + 'description' => __( 'Order the connection by term group.', 'wp-graphql-woocommerce' ), + ], + 'TERM_ID' => [ + 'value' => 'term_id', + 'description' => __( 'Order the connection by term id.', 'wp-graphql-woocommerce' ), + ], + 'TERM_ORDER' => [ + 'value' => 'term_order', + 'description' => __( 'Order the connection by term order.', 'wp-graphql-woocommerce' ), + ], + 'MENU_ORDER' => [ + 'value' => 'menu_order', + 'description' => __( 'Order the connection by woocommerce menu order.', 'wp-graphql-woocommerce' ), + ], + 'DESCRIPTION' => [ + 'value' => 'description', + 'description' => __( 'Order the connection by description.', 'wp-graphql-woocommerce' ), + ], + 'COUNT' => [ + 'value' => 'count', + 'description' => __( 'Order the connection by item count.', 'wp-graphql-woocommerce' ), + ], + ], + ] + ); + } +} \ No newline at end of file From 5aae46283e2af4eab3d5287009b2d27133da4bc1 Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Wed, 17 Jul 2024 00:24:47 +0300 Subject: [PATCH 2/6] Fix description --- .../enum/class-product-attributes-connection-orderby-enum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php index 28331af7..a94cf3c2 100644 --- a/includes/type/enum/class-product-attributes-connection-orderby-enum.php +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -19,7 +19,7 @@ public static function register() { register_graphql_enum_type( 'ProductAttributesConnectionOrderbyEnum', [ - 'description' => __( 'Taxonomy query operators', 'wp-graphql-woocommerce' ), + 'description' => __( 'Product attributes connection orderby enum', 'wp-graphql-woocommerce' ), 'values' => [ 'NAME' => [ 'value' => 'name', From 3bf1f17060f0a6ddc95c8dc168881280970d8e56 Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Wed, 17 Jul 2024 00:49:20 +0300 Subject: [PATCH 3/6] Add namespace --- .../enum/class-product-attributes-connection-orderby-enum.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php index a94cf3c2..716165de 100644 --- a/includes/type/enum/class-product-attributes-connection-orderby-enum.php +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -6,6 +6,8 @@ * @since 0.2.2 */ + namespace WPGraphQL\WooCommerce\Type\WPEnum; + /** * Class Product_Attributes_Connection_Orderby_Enum */ From 8d78bea61fbca0a0f36488eddf3d79f957a60c60 Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Thu, 25 Jul 2024 01:17:34 +0300 Subject: [PATCH 4/6] Lint fix --- includes/connection/class-wc-terms.php | 2 +- .../class-product-attributes-connection-orderby-enum.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/connection/class-wc-terms.php b/includes/connection/class-wc-terms.php index 4b1c46be..3df79ee8 100644 --- a/includes/connection/class-wc-terms.php +++ b/includes/connection/class-wc-terms.php @@ -120,7 +120,7 @@ public static function register_connections() { 'fromFieldName' => 'terms', 'connectionArgs' => self::get_connection_args( [ - 'orderby' => [ + 'orderby' => [ 'type' => 'ProductAttributesConnectionOrderbyEnum', 'description' => __( 'Field(s) to order terms by. Defaults to \'name\'.', 'wp-graphql-woocommerce' ), ], diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php index 716165de..cc066740 100644 --- a/includes/type/enum/class-product-attributes-connection-orderby-enum.php +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -6,13 +6,13 @@ * @since 0.2.2 */ - namespace WPGraphQL\WooCommerce\Type\WPEnum; +namespace WPGraphQL\WooCommerce\Type\WPEnum; /** * Class Product_Attributes_Connection_Orderby_Enum */ class Product_Attributes_Connection_Orderby_Enum { - /** + /** * Registers type * * @return void @@ -43,7 +43,7 @@ public static function register() { 'value' => 'term_order', 'description' => __( 'Order the connection by term order.', 'wp-graphql-woocommerce' ), ], - 'MENU_ORDER' => [ + 'MENU_ORDER' => [ 'value' => 'menu_order', 'description' => __( 'Order the connection by woocommerce menu order.', 'wp-graphql-woocommerce' ), ], @@ -59,4 +59,4 @@ public static function register() { ] ); } -} \ No newline at end of file +} From ca9b7704759368c2f302a9302cc78c1f6fc29bd5 Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Mon, 29 Jul 2024 11:55:17 +0300 Subject: [PATCH 5/6] Make minor commit --- .../enum/class-product-attributes-connection-orderby-enum.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php index cc066740..6647c4ae 100644 --- a/includes/type/enum/class-product-attributes-connection-orderby-enum.php +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -60,3 +60,4 @@ public static function register() { ); } } + From 6743797753b6fd8618c633f9be24129226695b5c Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Mon, 29 Jul 2024 11:55:50 +0300 Subject: [PATCH 6/6] Lint fix --- .../enum/class-product-attributes-connection-orderby-enum.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/type/enum/class-product-attributes-connection-orderby-enum.php b/includes/type/enum/class-product-attributes-connection-orderby-enum.php index 6647c4ae..cc066740 100644 --- a/includes/type/enum/class-product-attributes-connection-orderby-enum.php +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -60,4 +60,3 @@ public static function register() { ); } } -