WC_REST_Products_Catalog_Controller::catalog_generation_responseprivateWC 1.0

Generate catalog and return REST response.

This function orchestrates catalog generation and returns the appropriate response. In the future, it will check if a generation based on the file_info is in progress.

Method of the class: WC_REST_Products_Catalog_Controller{}

No Hooks.

Returns

WP_Error|WP_REST_Response. Response object on success, or WP_Error on failure.

Usage

// private - for code of main (parent) class only
$result = $this->catalog_generation_response( $file_info );
$file_info(array) (required)
File information with 'filepath', 'url', and 'directory' keys.

WC_REST_Products_Catalog_Controller::catalog_generation_response() code WC 10.4.3

private function catalog_generation_response( $file_info ) {
	// In the future, check if generation is in progress and return appropriate status.
	// For now, generate synchronously.
	$result = $this->generate_catalog_file( $file_info );
	if ( is_wp_error( $result ) ) {
		return $result;
	}

	return rest_ensure_response(
		array(
			'status'       => 'complete',
			'download_url' => $file_info['url'],
		)
	);
}