Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Shopify
ShopifyFetcher::build_graphql_query_string
Build GraphQL query string from filter arguments.
Method of the class: ShopifyFetcher{}
No Hooks.
Returns
String. GraphQL query string.
Usage
// private - for code of main (parent) class only $result = $this->build_graphql_query_string( $args ): string;
- $args(array) (required)
- Filter arguments.
ShopifyFetcher::build_graphql_query_string() ShopifyFetcher::build graphql query string code WC 10.8.1
private function build_graphql_query_string( array $args ): string {
$query_parts = array();
if ( isset( $args['status'] ) ) {
$query_parts[] = 'status:' . strtoupper( $args['status'] );
}
if ( isset( $args['product_type'] ) ) {
$query_parts[] = 'product_type:"' . $args['product_type'] . '"';
}
if ( isset( $args['vendor'] ) ) {
$query_parts[] = 'vendor:"' . $args['vendor'] . '"';
}
if ( isset( $args['handle'] ) ) {
$query_parts[] = 'handle:' . $args['handle'];
}
if ( isset( $args['created_after'] ) ) {
$query_parts[] = 'created_at:>=' . $args['created_after'];
}
if ( isset( $args['created_before'] ) ) {
$query_parts[] = 'created_at:<=' . $args['created_before'];
}
if ( isset( $args['ids'] ) ) {
$ids = is_array( $args['ids'] ) ? $args['ids'] : explode( ',', $args['ids'] );
$ids = array_filter( array_map( 'trim', $ids ) );
if ( ! empty( $ids ) ) {
$formatted_ids = array_map(
function ( $id ) {
return 'gid://shopify/Product/' . $id;
},
$ids
);
$query_parts[] = 'id:(' . implode( ' OR ', $formatted_ids ) . ')';
}
}
return implode( ' AND ', $query_parts );
}