mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
sorting fields added to cpt connections`
This commit is contained in:
@@ -105,41 +105,6 @@ class Coupon_Connection_Resolver extends AbstractConnectionResolver {
|
||||
$query_args['graphql_cursor_offset'] = $cursor_offset;
|
||||
$query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<';
|
||||
|
||||
/**
|
||||
* Map the orderby inputArgs to the WP_Query
|
||||
*/
|
||||
if ( ! empty( $this->args['where']['orderby'] ) && is_array( $this->args['where']['orderby'] ) ) {
|
||||
$query_args['orderby'] = array();
|
||||
foreach ( $this->args['where']['orderby'] as $orderby_input ) {
|
||||
/**
|
||||
* These orderby options should not include the order parameter.
|
||||
*/
|
||||
if ( in_array(
|
||||
$orderby_input['field'],
|
||||
array( 'post__in', 'post_name__in', 'post_parent__in' ),
|
||||
true
|
||||
) ) {
|
||||
$query_args['orderby'] = esc_sql( $orderby_input['field'] );
|
||||
} elseif ( ! empty( $orderby_input['field'] ) ) {
|
||||
$query_args['orderby'] = array(
|
||||
esc_sql( $orderby_input['field'] ) => esc_sql( $orderby_input['order'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert meta_value_num to seperate meta_value value field which our
|
||||
* graphql_wp_term_query_cursor_pagination_support knowns how to handle
|
||||
*/
|
||||
if ( isset( $query_args['orderby'] ) && 'meta_value_num' === $query_args['orderby'] ) {
|
||||
$query_args['orderby'] = array(
|
||||
'meta_value' => empty( $query_args['order'] ) ? 'DESC' : $query_args['order'], // WPCS: slow query ok.
|
||||
);
|
||||
unset( $query_args['order'] );
|
||||
$query_args['meta_type'] = 'NUMERIC';
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's no orderby params in the inputArgs, set order based on the first/last argument
|
||||
*/
|
||||
|
||||
@@ -123,41 +123,6 @@ class Order_Connection_Resolver extends AbstractConnectionResolver {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the orderby inputArgs to the WP_Query
|
||||
*/
|
||||
if ( ! empty( $this->args['where']['orderby'] ) && is_array( $this->args['where']['orderby'] ) ) {
|
||||
$query_args['orderby'] = array();
|
||||
foreach ( $this->args['where']['orderby'] as $orderby_input ) {
|
||||
/**
|
||||
* These orderby options should not include the order parameter.
|
||||
*/
|
||||
if ( in_array(
|
||||
$orderby_input['field'],
|
||||
array( 'post__in', 'post_name__in', 'post_parent__in' ),
|
||||
true
|
||||
) ) {
|
||||
$query_args['orderby'] = esc_sql( $orderby_input['field'] );
|
||||
} elseif ( ! empty( $orderby_input['field'] ) ) {
|
||||
$query_args['orderby'] = array(
|
||||
esc_sql( $orderby_input['field'] ) => esc_sql( $orderby_input['order'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert meta_value_num to seperate meta_value value field which our
|
||||
* graphql_wp_term_query_cursor_pagination_support knowns how to handle
|
||||
*/
|
||||
if ( isset( $query_args['orderby'] ) && 'meta_value_num' === $query_args['orderby'] ) {
|
||||
$query_args['orderby'] = array(
|
||||
'meta_value' => empty( $query_args['order'] ) ? 'DESC' : $query_args['order'], // WPCS: slow query ok.
|
||||
);
|
||||
unset( $query_args['order'] );
|
||||
$query_args['meta_type'] = 'NUMERIC';
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's no orderby params in the inputArgs, set order based on the first/last argument
|
||||
*/
|
||||
|
||||
@@ -160,41 +160,6 @@ class Product_Connection_Resolver extends AbstractConnectionResolver {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the orderby inputArgs to the WP_Query
|
||||
*/
|
||||
if ( ! empty( $this->args['where']['orderby'] ) && is_array( $this->args['where']['orderby'] ) ) {
|
||||
$query_args['orderby'] = array();
|
||||
foreach ( $this->args['where']['orderby'] as $orderby_input ) {
|
||||
/**
|
||||
* These orderby options should not include the order parameter.
|
||||
*/
|
||||
if ( in_array(
|
||||
$orderby_input['field'],
|
||||
array( 'post__in', 'post_name__in', 'post_parent__in' ),
|
||||
true
|
||||
) ) {
|
||||
$query_args['orderby'] = esc_sql( $orderby_input['field'] );
|
||||
} elseif ( ! empty( $orderby_input['field'] ) ) {
|
||||
$query_args['orderby'] = array(
|
||||
esc_sql( $orderby_input['field'] ) => esc_sql( $orderby_input['order'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert meta_value_num to seperate meta_value value field which our
|
||||
* graphql_wp_term_query_cursor_pagination_support knowns how to handle
|
||||
*/
|
||||
if ( isset( $query_args['orderby'] ) && 'meta_value_num' === $query_args['orderby'] ) {
|
||||
$query_args['orderby'] = array(
|
||||
'meta_value' => empty( $query_args['order'] ) ? 'DESC' : $query_args['order'], // WPCS: slow query ok.
|
||||
);
|
||||
unset( $query_args['order'] );
|
||||
$query_args['meta_type'] = 'NUMERIC';
|
||||
}
|
||||
|
||||
if ( isset( $query_args['post__in'] ) && empty( $query_args['post__in'] ) ) {
|
||||
$query_args['post__in'] = array( '0' );
|
||||
}
|
||||
|
||||
@@ -138,41 +138,6 @@ class Refund_Connection_Resolver extends AbstractConnectionResolver {
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the orderby inputArgs to the WP_Query
|
||||
*/
|
||||
if ( ! empty( $this->args['where']['orderby'] ) && is_array( $this->args['where']['orderby'] ) ) {
|
||||
$query_args['orderby'] = array();
|
||||
foreach ( $this->args['where']['orderby'] as $orderby_input ) {
|
||||
/**
|
||||
* These orderby options should not include the order parameter.
|
||||
*/
|
||||
if ( in_array(
|
||||
$orderby_input['field'],
|
||||
array( 'post__in', 'post_name__in', 'post_parent__in' ),
|
||||
true
|
||||
) ) {
|
||||
$query_args['orderby'] = esc_sql( $orderby_input['field'] );
|
||||
} elseif ( ! empty( $orderby_input['field'] ) ) {
|
||||
$query_args['orderby'] = array(
|
||||
esc_sql( $orderby_input['field'] ) => esc_sql( $orderby_input['order'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert meta_value_num to seperate meta_value value field which our
|
||||
* graphql_wp_term_query_cursor_pagination_support knowns how to handle
|
||||
*/
|
||||
if ( isset( $query_args['orderby'] ) && 'meta_value_num' === $query_args['orderby'] ) {
|
||||
$query_args['orderby'] = array(
|
||||
'meta_value' => empty( $query_args['order'] ) ? 'DESC' : $query_args['order'], // WPCS: slow query ok.
|
||||
);
|
||||
unset( $query_args['order'] );
|
||||
$query_args['meta_type'] = 'NUMERIC';
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's no orderby params in the inputArgs, set order based on the first/last argument
|
||||
*/
|
||||
|
||||
@@ -58,7 +58,7 @@ trait WC_Connection_Resolver {
|
||||
* Map the orderby inputArgs to the WP_Query
|
||||
*/
|
||||
if ( ! empty( $where_args['orderby'] ) && is_array( $where_args['orderby'] ) ) {
|
||||
$args['orderby'] = [];
|
||||
$args['orderby'] = array();
|
||||
foreach ( $where_args['orderby'] as $orderby_input ) {
|
||||
/**
|
||||
* These orderby options should not include the order parameter.
|
||||
@@ -69,6 +69,13 @@ trait WC_Connection_Resolver {
|
||||
true
|
||||
) ) {
|
||||
$args['orderby'] = esc_sql( $orderby_input['field'] );
|
||||
} elseif ( in_array(
|
||||
$orderby_input['field'],
|
||||
array( '_price', '_regular_price', '_sale_price' ),
|
||||
true
|
||||
) ) {
|
||||
$args['orderby'] = array( 'meta_value_num' => $orderby_input['order'] );
|
||||
$args['meta_key'] = esc_sql( $orderby_input['field'] ); // WPCS: slow query ok.
|
||||
} elseif ( ! empty( $orderby_input['field'] ) ) {
|
||||
$args['orderby'] = array(
|
||||
esc_sql( $orderby_input['field'] ) => esc_sql( $orderby_input['order'] ),
|
||||
@@ -77,18 +84,6 @@ trait WC_Connection_Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert meta_value_num to seperate meta_value value field which our
|
||||
* graphql_wp_term_query_cursor_pagination_support knowns how to handle
|
||||
*/
|
||||
if ( isset( $args['orderby'] ) && 'meta_value_num' === $args['orderby'] ) {
|
||||
$args['orderby'] = array(
|
||||
'meta_value' => empty( $args['order'] ) ? 'DESC' : $args['order'], // WPCS: slow query ok.
|
||||
);
|
||||
unset( $args['order'] );
|
||||
$args['meta_type'] = 'NUMERIC';
|
||||
}
|
||||
|
||||
if ( ! empty( $where_args['dateQuery'] ) ) {
|
||||
$args['date_query'] = $where_args['dateQuery'];
|
||||
}
|
||||
|
||||
@@ -21,34 +21,46 @@ class WC_Connection_Orderby_Enum {
|
||||
array(
|
||||
'description' => __( 'Field to order the connection by', 'wp-graphql-woocommerce' ),
|
||||
'values' => array(
|
||||
'SLUG' => array(
|
||||
'SLUG' => array(
|
||||
'value' => 'post_name',
|
||||
'description' => __( 'Order by slug', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'MODIFIED' => array(
|
||||
'MODIFIED' => array(
|
||||
'value' => 'post_modified',
|
||||
'description' => __( 'Order by last modified date', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'DATE' => array(
|
||||
'DATE' => array(
|
||||
'value' => 'post_date',
|
||||
'description' => __( 'Order by publish date', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'PARENT' => array(
|
||||
'PARENT' => array(
|
||||
'value' => 'post_parent',
|
||||
'description' => __( 'Order by parent ID', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'IN' => array(
|
||||
'IN' => array(
|
||||
'value' => 'post__in',
|
||||
'description' => __( 'Preserve the ID order given in the IN array', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'NAME_IN' => array(
|
||||
'NAME_IN' => array(
|
||||
'value' => 'post_name__in',
|
||||
'description' => __( 'Preserve slug order given in the NAME_IN array', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'MENU_ORDER' => array(
|
||||
'MENU_ORDER' => array(
|
||||
'value' => 'menu_order',
|
||||
'description' => __( 'Order by the menu order value', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'PRICE' => array(
|
||||
'value' => '_price',
|
||||
'description' => __( 'Order by the menu order value', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'REGULAR_PRICE' => array(
|
||||
'value' => '_regular_price',
|
||||
'description' => __( 'Order by the menu order value', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'SALE_PRICE' => array(
|
||||
'value' => '_sale_price',
|
||||
'description' => __( 'Order by the menu order value', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user