Automattic\WooCommerce\Admin\API\Reports\Categories

DataStore::get_noncached_data()publicWC 1.0

Returns the report data based on normalized parameters. Will be called by get_data if there is no data in cache.

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

Хуков нет.

Возвращает

stdClass|WP_Error. Data object { totals: *, intervals: array, total: int, pages: int, page_no: int }, or error.

Использование

$DataStore = new DataStore();
$DataStore->get_noncached_data( $query_args );
$query_args(массив) (обязательный)
Query parameters.

Заметки

  • Смотрите: get_data

Код DataStore::get_noncached_data() WC 9.3.3

public function get_noncached_data( $query_args ) {
	global $wpdb;

	$table_name = self::get_db_table_name();
	$this->initialize_queries();

	$data = (object) array(
		'data'    => array(),
		'total'   => 0,
		'pages'   => 0,
		'page_no' => 0,
	);

	$this->subquery->add_sql_clause( 'select', $this->selected_columns( $query_args ) );
	$included_categories = $this->get_included_categories_array( $query_args );
	$this->add_sql_query_params( $query_args );

	if ( count( $included_categories ) > 0 ) {
		$fields    = $this->get_fields( $query_args );
		$ids_table = $this->get_ids_table( $included_categories, 'category_id' );

		$this->add_sql_clause( 'select', $this->format_join_selections( array_merge( array( 'category_id' ), $fields ), array( 'category_id' ) ) );
		$this->add_sql_clause( 'from', '(' );
		$this->add_sql_clause( 'from', $this->subquery->get_query_statement() );
		$this->add_sql_clause( 'from', ") AS {$table_name}" );
		$this->add_sql_clause(
			'right_join',
			"RIGHT JOIN ( {$ids_table} ) AS default_results
			ON default_results.category_id = {$table_name}.category_id"
		);

		$categories_query = $this->get_query_statement();
	} else {
		$this->subquery->add_sql_clause( 'order_by', $this->get_sql_clause( 'order_by' ) );
		$categories_query = $this->subquery->get_query_statement();
	}
	$categories_data = $wpdb->get_results(
		$categories_query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		ARRAY_A
	);

	if ( null === $categories_data ) {
		return new \WP_Error( 'woocommerce_analytics_categories_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce' ), array( 'status' => 500 ) );
	}

	$record_count = count( $categories_data );
	$total_pages  = (int) ceil( $record_count / $query_args['per_page'] );
	if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
		return $data;
	}

	$categories_data = $this->page_records( $categories_data, $query_args['page'], $query_args['per_page'] );
	$this->include_extended_info( $categories_data, $query_args );
	$categories_data = array_map( array( $this, 'cast_numbers' ), $categories_data );
	$data            = (object) array(
		'data'    => $categories_data,
		'total'   => $record_count,
		'pages'   => $total_pages,
		'page_no' => (int) $query_args['page'],
	);

	return $data;
}