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

ShopifyMapper::map_product_classificationprivateWC 1.0

Maps product classification fields from Shopify.

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

Хуков нет.

Возвращает

Массив. Product classification data.

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

// private - только в коде основоного (родительского) класса
$result = $this->map_product_classification( $shopify_product ): array;
$shopify_product(объект) (обязательный)
The Shopify product data.

Код ShopifyMapper::map_product_classification() WC 11.0.1

private function map_product_classification( object $shopify_product ): array {
	$classification = array();

	// Product type - check both camelCase and snake_case for compatibility.
	$product_type = null;
	if ( property_exists( $shopify_product, 'productType' ) && $shopify_product->productType ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
		$product_type = $shopify_product->productType; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
	} elseif ( property_exists( $shopify_product, 'product_type' ) && $shopify_product->product_type ) {
		$product_type = $shopify_product->product_type;
	}

	if ( $product_type ) {
		$classification['product_type'] = array(
			'name' => $product_type,
			'slug' => sanitize_title( $product_type ),
		);
	}

	// Standard category.
	if ( property_exists( $shopify_product, 'category' ) && is_object( $shopify_product->category ) ) {
		$classification['standard_category'] = array(
			'name' => $shopify_product->category->name ?? '',
			'slug' => sanitize_title( $shopify_product->category->name ?? '' ),
		);
	}

	// Gift card detection - check both camelCase and snake_case for compatibility.
	if ( property_exists( $shopify_product, 'isGiftCard' ) ) {
		$classification['is_gift_card'] = $shopify_product->isGiftCard; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
	} elseif ( property_exists( $shopify_product, 'is_gift_card' ) ) {
		$classification['is_gift_card'] = $shopify_product->is_gift_card;
	}

	if ( property_exists( $shopify_product, 'requiresSellingPlan' ) ) {
		$classification['requires_subscription'] = $shopify_product->requiresSellingPlan; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- GraphQL uses camelCase.
	} elseif ( property_exists( $shopify_product, 'requires_selling_plan' ) ) {
		$classification['requires_subscription'] = $shopify_product->requires_selling_plan;
	}

	return $classification;
}