Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Feb 9, 2016
1 parent d23c316 commit 236c063
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions includes/class-wc-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,8 @@ public function wpseo_metakey() {
* @param mixed $q
*/
public function product_query( $q ) {
$ordering = $this->get_catalog_ordering_args();

// Ordering query vars
$ordering = $this->get_catalog_ordering_args();
$q->set( 'orderby', $ordering['orderby'] );
$q->set( 'order', $ordering['order'] );
if ( isset( $ordering['meta_key'] ) ) {
Expand All @@ -342,11 +341,7 @@ public function product_query( $q ) {
$q->set( 'meta_query', $this->get_meta_query( $q->get( 'meta_query' ) ) );
$q->set( 'tax_query', $this->get_tax_query( $q->get( 'tax_query' ) ) );
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ) );

// Set a special variable
$q->set( 'wc_query', 'product_query' );

// Filterable post__in
$q->set( 'post__in', array_unique( apply_filters( 'loop_shop_post_in', array() ) ) );

do_action( 'woocommerce_product_query', $q, $this );
Expand Down Expand Up @@ -461,16 +456,12 @@ public function order_by_rating_post_clauses( $args ) {
global $wpdb;

$args['fields'] .= ", AVG( $wpdb->commentmeta.meta_value ) as average_rating ";

$args['where'] .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";

$args['join'] .= "
$args['where'] .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";
$args['join'] .= "
LEFT OUTER JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID)
LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)
";

$args['orderby'] = "average_rating DESC, $wpdb->posts.post_date DESC";

$args['groupby'] = "$wpdb->posts.ID";

return $args;
Expand Down Expand Up @@ -537,23 +528,17 @@ private function price_filter_meta_query() {
* @return array
*/
public function rating_filter_meta_query() {
if ( isset( $_GET['min_rating'] ) ) {
$min = isset( $_GET['min_rating'] ) ? floatval( $_GET['min_rating'] ) : 0;
return array(
'key' => '_wc_average_rating',
'value' => $min,
'compare' => '>=',
'type' => 'DECIMAL',
'rating_filter' => true
);
}
return array();
return isset( $_GET['min_rating'] ) ? array(
'key' => '_wc_average_rating',
'value' => isset( $_GET['min_rating'] ) ? floatval( $_GET['min_rating'] ) : 0,
'compare' => '>=',
'type' => 'DECIMAL',
'rating_filter' => true
) : array();
}

/**
* Returns a meta query to handle product visibility.
*
* @access public
* @param string $compare (default: 'IN')
* @return array
*/
Expand Down Expand Up @@ -599,7 +584,8 @@ public function get_tax_query( $tax_query = array() ) {
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $data['terms'],
'operator' => 'and' === $data['query_type'] ? 'AND' : 'IN'
'operator' => 'and' === $data['query_type'] ? 'AND' : 'IN',
'include_children' => false
);
}
}
Expand Down

0 comments on commit 236c063

Please sign in to comment.