Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Product_Attributes_Connection_Orderby_Enum with MENU_ORDER #876

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/class-type-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions includes/class-wp-graphql-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 8 additions & 1 deletion includes/connection/class-wc-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* WPEnum Type - Product_Attributes_Connection_Orderby_Enum
*
* @package WPGraphQL\WooCommerce\Type\WPEnum
* @since 0.2.2
*/

namespace WPGraphQL\WooCommerce\Type\WPEnum;

/**
* Class Product_Attributes_Connection_Orderby_Enum
*/
class Product_Attributes_Connection_Orderby_Enum {
/**
* Registers type
*
* @return void
*/
public static function register() {
register_graphql_enum_type(
'ProductAttributesConnectionOrderbyEnum',
[
'description' => __( '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' ),
],
],
]
);
}
}
Loading