Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Shopify

ShopifyMapper::map_basic_product_fieldsprivateWC 1.0

Maps basic product fields from Shopify to WooCommerce format.

Method of the class: ShopifyMapper{}

No Hooks.

Returns

Array. Basic product field mappings.

Usage

// private - for code of main (parent) class only
$result = $this->map_basic_product_fields( $shopify_product, $is_variable ): array;
$shopify_product(object) (required)
The Shopify product data.
$is_variable(true|false) (required)
Whether this is a variable product.

ShopifyMapper::map_basic_product_fields() code WC 10.8.1

private function map_basic_product_fields( object $shopify_product, bool $is_variable ): array {
	$basic_data = array();

	$basic_data['is_variable']         = $is_variable;
	$basic_data['original_product_id'] = ! empty( $shopify_product->id ) ? basename( $shopify_product->id ) : null;

	// Basic Product Fields.
	$basic_data['name']              = wc_clean( $shopify_product->title );
	$basic_data['slug']              = sanitize_title( $shopify_product->handle );
	$basic_data['description']       = wp_kses_post( $shopify_product->descriptionHtml ?? '' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
	$basic_data['short_description'] = wp_kses_post( $shopify_product->descriptionPlainSummary ?? '' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
	$basic_data['status']            = $this->get_woo_product_status( $shopify_product );
	$basic_data['date_created_gmt']  = $shopify_product->createdAt; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.

	// Enhanced date handling.
	if ( property_exists( $shopify_product, 'updatedAt' ) ) {
		$basic_data['date_modified_gmt'] = $shopify_product->updatedAt; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
	}

	// Catalog Visibility & Original URL.
	$basic_data['catalog_visibility'] = 'visible';
	$basic_data['original_url']       = null;
	if ( property_exists( $shopify_product, 'onlineStoreUrl' ) ) {
		if ( null === $shopify_product->onlineStoreUrl ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
			$basic_data['catalog_visibility'] = 'hidden';
		} else {
			$basic_data['original_url'] = $shopify_product->onlineStoreUrl; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
		}
	}

	$enhanced_status = $this->map_enhanced_status( $shopify_product );
	$basic_data      = array_merge( $basic_data, $enhanced_status );

	// Taxonomies.
	$basic_data['categories'] = $this->get_mapped_categories( $shopify_product );
	$basic_data['tags']       = $this->get_mapped_tags( $shopify_product );

	// Enhanced product classification.
	$classification = $this->map_product_classification( $shopify_product );
	$basic_data     = array_merge( $basic_data, $classification );

	// Brand (Vendor).
	$brand_name          = $shopify_product->vendor ?? null;
	$basic_data['brand'] = $brand_name ? array(
		'name' => wc_clean( $brand_name ),
		'slug' => sanitize_title( $brand_name ),
	) : null;

	return $basic_data;
}