DataStore::add_sql_query_params()protectedWC 1.0

Return the database query with parameters used for Categories report: time span and order status.

Метод класса: DataStore{}

Хуков нет.


null. Ничего (null).


// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_sql_query_params( $query_args );
$query_args(массив) (обязательный)
Query arguments supplied by the user.

Код DataStore::add_sql_query_params() WC 8.7.0

protected function add_sql_query_params( $query_args ) {
	global $wpdb;
	$order_product_lookup_table = self::get_db_table_name();

	$this->add_time_period_sql_params( $query_args, $order_product_lookup_table );

	// join wp_order_product_lookup_table with relationships and taxonomies
	// @todo How to handle custom product tables?
	$this->subquery->add_sql_clause( 'left_join', "LEFT JOIN {$wpdb->term_relationships} ON {$order_product_lookup_table}.product_id = {$wpdb->term_relationships}.object_id" );
	// Adding this (inner) JOIN as a LEFT JOIN for ordering purposes. See comment in add_order_by_params().
	$this->subquery->add_sql_clause( 'left_join', "JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id" );

	$included_categories = $this->get_included_categories( $query_args );
	if ( $included_categories ) {
		$this->subquery->add_sql_clause( 'where', "AND {$wpdb->term_relationships}.term_taxonomy_id IN ({$included_categories})" );

		// Limit is left out here so that the grouping in code by PHP can be applied correctly.
		// This also needs to be put after the term_taxonomy JOIN so that we can match the correct term name.
		$this->add_order_by_params( $query_args, 'outer', 'default_results.category_id' );
	} else {
		$this->add_order_by_params( $query_args, 'inner', "{$wpdb->term_relationships}.term_taxonomy_id" );

	$this->add_order_status_clause( $query_args, $order_product_lookup_table, $this->subquery );
	$this->subquery->add_sql_clause( 'where', "AND {$wpdb->term_taxonomy}.taxonomy = 'product_cat'" );