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

WebflowFetcher::fetch_batchpublicWC 1.0

Fetches a batch of products from the Webflow REST API.

Method of the class: WebflowFetcher{}

No Hooks.

Returns

Array{items:. array, cursor: ?string, has_next_page: bool}

Usage

$WebflowFetcher = new WebflowFetcher();
$WebflowFetcher->fetch_batch( $args ): array;
$args(array) (required)
Arguments for fetching. Supported keys:
  • 'limit': Max number of items per batch .
  • 'after_cursor': Stringified next-offset for pagination (optional).
    Default: 50, capped at 100)

WebflowFetcher::fetch_batch() code WC 11.0.0

public function fetch_batch( array $args ): array {
	$site_id = $this->webflow_client->get_site_id();
	if ( is_wp_error( $site_id ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::warning( 'Failed to fetch Webflow products: ' . $site_id->get_error_message() );
		return $this->empty_batch();
	}

	$limit  = (int) ( $args['limit'] ?? 50 );
	$limit  = max( 1, min( $limit, self::MAX_PAGE_SIZE ) );
	$offset = 0;
	if ( isset( $args['after_cursor'] ) && is_numeric( $args['after_cursor'] ) ) {
		$offset = max( 0, (int) $args['after_cursor'] );
	}

	$query = array(
		'limit'  => $limit,
		'offset' => $offset,
	);

	$response = $this->webflow_client->rest_request( "/sites/{$site_id}/products", $query );

	if ( is_wp_error( $response ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::warning( 'Failed to fetch products from Webflow: ' . $response->get_error_message() );
		return $this->empty_batch();
	}

	if ( ! is_object( $response ) || ! isset( $response->items ) || ! is_array( $response->items ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::warning( 'Invalid Webflow response: missing items array.' );
		return $this->empty_batch();
	}

	$items    = $response->items;
	$count    = count( $items );
	$total    = isset( $response->pagination->total ) ? (int) $response->pagination->total : ( $offset + $count );
	$next     = $offset + $count;
	$has_next = $count > 0 && $next < $total;

	$this->ensure_category_cache_loaded( $site_id );
	$this->decorate_items_with_categories( $items );

	// The cursor is simply the next offset. Unlike Shopify's stable cursors, offset paging can
	// skip or double-import items if the Webflow catalog changes (a product added or removed)
	// between batches. Acceptable here given Webflow's API offers no stable cursor.
	return array(
		'items'         => $items,
		'cursor'        => $has_next ? (string) $next : null,
		'has_next_page' => $has_next,
	);
}