Automattic\WooCommerce\Admin\API\Reports\Products

DataStore::add_from_sql_params()protectedWC 1.0

Fills FROM clause of SQL request based on user supplied parameters.

Method of the class: DataStore{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->add_from_sql_params( $query_args, $arg_name, $id_cell );
$query_args(array) (required)
Parameters supplied by the user.
$arg_name(string) (required)
Target of the JOIN sql param.
$id_cell(string) (required)
ID cell identifier, like table_name.id_column_name.

DataStore::add_from_sql_params() code WC 8.9.0

protected function add_from_sql_params( $query_args, $arg_name, $id_cell ) {
	global $wpdb;

	$type = 'join';
	// Order by product name requires extra JOIN.
	switch ( $query_args['orderby'] ) {
		case 'product_name':
			$join = " JOIN {$wpdb->posts} AS _products ON {$id_cell} = _products.ID";
			break;
		case 'sku':
			$join = " LEFT JOIN {$wpdb->postmeta} AS postmeta ON {$id_cell} = postmeta.post_id AND postmeta.meta_key = '_sku'";
			break;
		case 'variations':
			$type = 'left_join';
			$join = "LEFT JOIN ( SELECT post_parent, COUNT(*) AS variations FROM {$wpdb->posts} WHERE post_type = 'product_variation' GROUP BY post_parent ) AS _variations ON {$id_cell} = _variations.post_parent";
			break;
		default:
			$join = '';
			break;
	}
	if ( $join ) {
		if ( 'inner' === $arg_name ) {
			$this->subquery->add_sql_clause( $type, $join );
		} else {
			$this->add_sql_clause( $type, $join );
		}
	}
}