Automattic\WooCommerce\Internal\CLI\Migrator\Core

ProductsController::display_product_progresspublicWC 1.0

Display progress indicator for individual product imports.

Метод класса: ProductsController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$ProductsController = new ProductsController();
$ProductsController->display_product_progress( $current_index, $total_count, $product_name, ?array $result ): void;
$current_index(int) (обязательный)
Current product index (1-based).
$total_count(int) (обязательный)
Total number of products in batch.
$product_name(строка) (обязательный)
Name of the product being processed.
?array $result(обязательный)
.

Код ProductsController::display_product_progress() WC 10.3.4

public function display_product_progress( int $current_index, int $total_count, string $product_name, ?array $result ): void {
	if ( null === $result ) {
		return;
	}

	$display_name = strlen( $product_name ) > 40 ? substr( $product_name, 0, 37 ) . '...' : $product_name;

	$status_char  = '✓';
	$status_color = '%G';

	if ( 'error' === $result['status'] ) {
		$status_char  = '✗';
		$status_color = '%R';
	} elseif ( 'success' === $result['status'] && 'skipped' === $result['action'] ) {
		$status_char  = '−';
		$status_color = '%Y';
	}

	$progress = sprintf( '[%d/%d]', $current_index, $total_count );

	if ( 1 === $current_index ) {
		WP_CLI::line( '' );
	}

	WP_CLI::line(
		WP_CLI::colorize(
			sprintf( '%s%s%s %s %s', $status_color, $status_char, '%n', $progress, $display_name )
		)
	);
}