Skip to content

Commit 1424f57

Browse files
authored
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
1 parent 61b99ea commit 1424f57

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

includes/class-type-registry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function init() {
4848
Type\WPEnum\Currency_Enum::register();
4949
Type\WPEnum\Shipping_Location_Type_Enum::register();
5050
Type\WPEnum\WC_Setting_Type_Enum::register();
51+
Type\WPEnum\Product_Attributes_Connection_Orderby_Enum::register();
5152

5253
/**
5354
* InputObjects.

includes/class-wp-graphql-woocommerce.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ private function includes() {
246246
require $include_directory_path . 'type/enum/class-currency-enum.php';
247247
require $include_directory_path . 'type/enum/class-shipping-location-type-enum.php';
248248
require $include_directory_path . 'type/enum/class-wc-setting-type-enum.php';
249+
require $include_directory_path . 'type/enum/class-product-attributes-connection-orderby-enum.php';
249250

250251
// Include interface type class files.
251252
require $include_directory_path . 'type/interface/class-attribute.php';

includes/connection/class-wc-terms.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ public static function register_connections() {
118118
'toType' => 'TermNode',
119119
'queryClass' => 'WP_Term_Query',
120120
'fromFieldName' => 'terms',
121-
'connectionArgs' => self::get_connection_args(),
121+
'connectionArgs' => self::get_connection_args(
122+
[
123+
'orderby' => [
124+
'type' => 'ProductAttributesConnectionOrderbyEnum',
125+
'description' => __( 'Field(s) to order terms by. Defaults to \'name\'.', 'wp-graphql-woocommerce' ),
126+
],
127+
]
128+
),
122129
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
123130
if ( ! $source->is_taxonomy() ) {
124131
throw new UserError( __( 'Invalid product attribute', 'wp-graphql-woocommerce' ) );
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* WPEnum Type - Product_Attributes_Connection_Orderby_Enum
4+
*
5+
* @package WPGraphQL\WooCommerce\Type\WPEnum
6+
* @since 0.2.2
7+
*/
8+
9+
namespace WPGraphQL\WooCommerce\Type\WPEnum;
10+
11+
/**
12+
* Class Product_Attributes_Connection_Orderby_Enum
13+
*/
14+
class Product_Attributes_Connection_Orderby_Enum {
15+
/**
16+
* Registers type
17+
*
18+
* @return void
19+
*/
20+
public static function register() {
21+
register_graphql_enum_type(
22+
'ProductAttributesConnectionOrderbyEnum',
23+
[
24+
'description' => __( 'Product attributes connection orderby enum', 'wp-graphql-woocommerce' ),
25+
'values' => [
26+
'NAME' => [
27+
'value' => 'name',
28+
'description' => __( 'Order the connection by name.', 'wp-graphql-woocommerce' ),
29+
],
30+
'SLUG' => [
31+
'value' => 'slug',
32+
'description' => __( 'Order the connection by slug.', 'wp-graphql-woocommerce' ),
33+
],
34+
'TERM_GROUP' => [
35+
'value' => 'term_group',
36+
'description' => __( 'Order the connection by term group.', 'wp-graphql-woocommerce' ),
37+
],
38+
'TERM_ID' => [
39+
'value' => 'term_id',
40+
'description' => __( 'Order the connection by term id.', 'wp-graphql-woocommerce' ),
41+
],
42+
'TERM_ORDER' => [
43+
'value' => 'term_order',
44+
'description' => __( 'Order the connection by term order.', 'wp-graphql-woocommerce' ),
45+
],
46+
'MENU_ORDER' => [
47+
'value' => 'menu_order',
48+
'description' => __( 'Order the connection by woocommerce menu order.', 'wp-graphql-woocommerce' ),
49+
],
50+
'DESCRIPTION' => [
51+
'value' => 'description',
52+
'description' => __( 'Order the connection by description.', 'wp-graphql-woocommerce' ),
53+
],
54+
'COUNT' => [
55+
'value' => 'count',
56+
'description' => __( 'Order the connection by item count.', 'wp-graphql-woocommerce' ),
57+
],
58+
],
59+
]
60+
);
61+
}
62+
}

0 commit comments

Comments
 (0)