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

WebflowMapper::resolve_variation_attributesprivateWC 1.0

Resolve a SKU's sku-values (property_id => enum_id) into a human-readable attribute_name => option_name array using the property lookup.

Method of the class: WebflowMapper{}

No Hooks.

Returns

Array.

Usage

// private - for code of main (parent) class only
$result = $this->resolve_variation_attributes( $sku_field, $property_lookup ): array;
$sku_field(object) (required)
SKU fieldData.
$property_lookup(array) (required)
Property lookup map.

WebflowMapper::resolve_variation_attributes() code WC 11.0.0

private function resolve_variation_attributes( object $sku_field, array $property_lookup ): array {
	$resolved   = array();
	$values_key = 'sku-values';
	if ( ! isset( $sku_field->{$values_key} ) ) {
		return $resolved;
	}

	$values = $sku_field->{$values_key};
	if ( ! is_object( $values ) && ! is_array( $values ) ) {
		return $resolved;
	}

	foreach ( (array) $values as $property_id => $enum_id ) {
		$property_id = (string) $property_id;
		$enum_id     = (string) $enum_id;
		if ( ! isset( $property_lookup[ $property_id ] ) ) {
			continue;
		}
		$property_name = $property_lookup[ $property_id ]['name'];
		$option_name   = $property_lookup[ $property_id ]['enums'][ $enum_id ] ?? null;
		if ( null === $option_name ) {
			continue;
		}
		$resolved[ sanitize_text_field( $property_name ) ] = sanitize_text_field( $option_name );
	}

	return $resolved;
}