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

WebflowFetcher::ensure_category_cache_loadedprivateWC 1.0

Ensures the category cache has been resolved at most once per fetcher instance.

Method of the class: WebflowFetcher{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->ensure_category_cache_loaded( $site_id ): void;
$site_id(string) (required)
Webflow site ID.

WebflowFetcher::ensure_category_cache_loaded() code WC 11.0.1

private function ensure_category_cache_loaded( string $site_id ): void {
	if ( null !== $this->category_cache ) {
		return;
	}

	$this->category_cache = array();

	$collections_response = $this->webflow_client->rest_request( "/sites/{$site_id}/collections" );
	if ( is_wp_error( $collections_response ) ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::debug( 'Could not load Webflow collections list (categories will not be resolved): ' . $collections_response->get_error_message() );
		return;
	}

	$collections = $this->extract_collections_list( $collections_response );
	$category_id = $this->find_category_collection_id( $collections );

	if ( null === $category_id ) {
		// @phpstan-ignore-next-line class.notFound
		\WP_CLI::debug( 'No "category" collection found on Webflow site; product categories will be skipped.' );
		return;
	}

	$this->category_cache = $this->load_collection_items_map( $category_id );
}