Skip to content

Commit

Permalink
feat: Add Product_Attributes_Connection_Orderby_Enum with MENU_ORDER (#…
Browse files Browse the repository at this point in the history
…876)

* Add Product_Attributes_Connection_Orderby_Enum with MENU_ORDER

* Fix description

* Add namespace

* Lint fix

* Make minor commit

* Lint fix
  • Loading branch information
alexookah authored Jul 29, 2024
1 parent 61b99ea commit 1424f57
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
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' ),
],
],
]
);
}
}

0 comments on commit 1424f57

Please sign in to comment.