From 1424f57ff8324c3936491aa03fada8c3f3c2793a Mon Sep 17 00:00:00 2001 From: Alex Lykesas Date: Tue, 30 Jul 2024 00:15:49 +0300 Subject: [PATCH] feat: Add Product_Attributes_Connection_Orderby_Enum with MENU_ORDER (#876) * Add Product_Attributes_Connection_Orderby_Enum with MENU_ORDER * Fix description * Add namespace * Lint fix * Make minor commit * Lint fix --- 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 | 62 +++++++++++++++++++ 4 files changed, 72 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..3df79ee8 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..cc066740 --- /dev/null +++ b/includes/type/enum/class-product-attributes-connection-orderby-enum.php @@ -0,0 +1,62 @@ + __( 'Product attributes connection orderby enum', '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' ), + ], + ], + ] + ); + } +}