Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow

WebflowFetcher::fetch_total_countpublicWC 1.0

Fetches the total count of products from Webflow.

Method of the class: WebflowFetcher{}

No Hooks.

Returns

Int. Total product count, or 0 on failure.

Usage

$WebflowFetcher = new WebflowFetcher();
$WebflowFetcher->fetch_total_count( $args ): int;
$args(array) (required)
Filter arguments (unused; Webflow's products endpoint does not accept filters).

WebflowFetcher::fetch_total_count() code WC 11.0.0

public function fetch_total_count( array $args ): int {
	unset( $args );
	// Webflow does not support filtered count queries here.

	$site_id = $this->webflow_client->get_site_id();
	if ( is_wp_error( $site_id ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::warning( 'Could not fetch Webflow product count: ' . $site_id->get_error_message() );
		return 0;
	}

	$response = $this->webflow_client->rest_request(
		"/sites/{$site_id}/products",
		array(
			'limit'  => 1,
			'offset' => 0,
		)
	);

	if ( is_wp_error( $response ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::warning( 'Could not fetch Webflow product count: ' . $response->get_error_message() );
		return 0;
	}

	if ( ! is_object( $response ) || ! isset( $response->pagination->total ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::warning( 'Unexpected response from Webflow products endpoint - missing pagination.total.' );
		return 0;
	}

	return (int) $response->pagination->total;
}