Automattic\WooCommerce\Internal\CLI\Migrator\Core
MigratorTracker::track_product_types
Track product types from mapped data and import results.
Only count product types for successfully imported products to ensure telemetry accuracy.
Method of the class: MigratorTracker{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->track_product_types( $mapped_data, $batch_results ): void;
- $mapped_data(array) (required)
- Array of mapped product data.
- $batch_results(array) (required)
- Results from the batch import.
MigratorTracker::track_product_types() MigratorTracker::track product types code WC 10.8.1
private function track_product_types( array $mapped_data, array $batch_results ): void {
$successful_results = array_filter(
$batch_results['results'] ?? array(),
function ( $result ) {
return 'success' === ( $result['status'] ?? '' ) && 'skipped' !== ( $result['action'] ?? '' );
}
);
// Only track types for successfully imported products.
foreach ( $successful_results as $index => $result ) {
if ( ! isset( $mapped_data[ $index ] ) ) {
continue;
}
$product = $mapped_data[ $index ];
$type = $product['type'] ?? 'simple';
if ( ! isset( $this->current_session['product_types'][ $type ] ) ) {
$this->current_session['product_types'][ $type ] = 0;
}
++$this->current_session['product_types'][ $type ];
}
}