Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Shopify

ShopifyFetcher::fetch_batchpublicWC 1.0

Fetches a batch of products from the Shopify GraphQL API.

Method of the class: ShopifyFetcher{}

No Hooks.

Returns

Array. An array containing: 'items' => array Raw product edges fetched from Shopify. 'cursor' => ?string The cursor for the next page, or null if no more pages. 'has_next_page' => bool Indicates if there are more pages to fetch.

Usage

$ShopifyFetcher = new ShopifyFetcher();
$ShopifyFetcher->fetch_batch( $args ): array;
$args(array) (required)
Arguments for fetching. Supported keys:
  • 'limit': Max number of items per batch .
  • 'after_cursor': Cursor for pagination (optional).
  • 'query_filter': GraphQL query filter string (optional).
  • 'variants_per_product': Max variants per product (default: 100).
    Default: 50)

ShopifyFetcher::fetch_batch() code WC 10.8.1

public function fetch_batch( array $args ): array {
	$variables = $this->build_graphql_variables( $args );

	$response_data = $this->shopify_client->graphql_request( self::SHOPIFY_PRODUCT_QUERY, $variables );

	if ( is_wp_error( $response_data ) ) {
		\WP_CLI::warning( 'Failed to fetch products via GraphQL: ' . $response_data->get_error_message() );
		return array(
			'items'         => array(),
			'cursor'        => null,
			'has_next_page' => false,
		);
	}

	if ( ! isset( $response_data->products->edges ) ) {
		\WP_CLI::warning( 'Invalid GraphQL response structure - missing products.edges field.' );
		return array(
			'items'         => array(),
			'cursor'        => null,
			'has_next_page' => false,
		);
	}

	$items       = $response_data->products->edges;
	$page_info   = $response_data->products->pageInfo ?? null;
	$last_cursor = null;

	if ( ! empty( $items ) ) {
		$last_edge   = end( $items );
		$last_cursor = $last_edge->cursor ?? null;
	}

	return array(
		'items'         => $items,
		'cursor'        => $last_cursor,
		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL response property
		'has_next_page' => $page_info ? $page_info->hasNextPage : false,
	);
}