Automattic\WooCommerce\Admin\API\Reports\Variations
DataStore::get_order_item_by_attribute_subquery
Generate a subquery for order_item_id based on the attribute filters.
Method of the class: DataStore{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->get_order_item_by_attribute_subquery( $query_args );
- $query_args(array) (required)
- Query arguments supplied by the user.
DataStore::get_order_item_by_attribute_subquery() DataStore::get order item by attribute subquery code WC 10.7.0
protected function get_order_item_by_attribute_subquery( $query_args ) {
$order_product_lookup_table = self::get_db_table_name();
$attribute_subqueries = $this->get_attribute_subqueries( $query_args );
if ( $attribute_subqueries['join'] && $attribute_subqueries['where'] ) {
// Perform a subquery for DISTINCT order items that match our attribute filters.
$attr_subquery = new SqlQuery( $this->context . '_attribute_subquery' );
$attr_subquery->add_sql_clause( 'select', "DISTINCT {$order_product_lookup_table}.order_item_id" );
$attr_subquery->add_sql_clause( 'from', $order_product_lookup_table );
if ( $this->should_exclude_simple_products( $query_args ) ) {
$attr_subquery->add_sql_clause( 'where', "AND {$order_product_lookup_table}.variation_id != 0" );
}
foreach ( $attribute_subqueries['join'] as $attribute_join ) {
$attr_subquery->add_sql_clause( 'join', $attribute_join );
}
$operator = $this->get_match_operator( $query_args );
$attr_subquery->add_sql_clause( 'where', 'AND (' . implode( " {$operator} ", $attribute_subqueries['where'] ) . ')' );
return "AND {$order_product_lookup_table}.order_item_id IN ({$attr_subquery->get_query_statement()})";
}
return false;
}