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

WebflowMapper::map_categoriesprivateWC 1.0

Read the pre-resolved categories the fetcher attached to the item.

Method of the class: WebflowMapper{}

No Hooks.

Returns

Array.

Usage

// private - for code of main (parent) class only
$result = $this->map_categories( $platform_data ): array;
$platform_data(object) (required)
Raw item.

WebflowMapper::map_categories() code WC 11.0.1

private function map_categories( object $platform_data ): array {
	$resolved_key = '_resolved_categories';
	if ( ! isset( $platform_data->{$resolved_key} ) || ! is_array( $platform_data->{$resolved_key} ) ) {
		return array();
	}

	$categories = array();
	foreach ( $platform_data->{$resolved_key} as $entry ) {
		if ( is_array( $entry ) && ! empty( $entry['name'] ) ) {
			$categories[] = array(
				'name' => sanitize_text_field( (string) $entry['name'] ),
				'slug' => sanitize_title( (string) ( $entry['slug'] ?? $entry['name'] ) ),
			);
		} elseif ( is_object( $entry ) && ! empty( $entry->name ) ) {
			$categories[] = array(
				'name' => sanitize_text_field( (string) $entry->name ),
				'slug' => sanitize_title( (string) ( $entry->slug ?? $entry->name ) ),
			);
		}
	}
	return $categories;
}