Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Shopify
ShopifyMapper::map_product_classification
Maps product classification fields from Shopify.
Method of the class: ShopifyMapper{}
No Hooks.
Returns
Array. Product classification data.
Usage
// private - for code of main (parent) class only $result = $this->map_product_classification( $shopify_product ): array;
- $shopify_product(object) (required)
- The Shopify product data.
ShopifyMapper::map_product_classification() ShopifyMapper::map product classification code WC 10.8.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;
}