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

WebflowMapper::map_simple_dataprivateWC 1.0

Map fields specific to a simple (single-SKU) product.

Method of the class: WebflowMapper{}

No Hooks.

Returns

Array.

Usage

// private - for code of main (parent) class only
$result = $this->map_simple_data( $skus ): array;
$skus(array<int,object>) (required)
SKUs.

WebflowMapper::map_simple_data() code WC 11.0.1

private function map_simple_data( array $skus ): array {
	$simple = array(
		'sku'            => null,
		'regular_price'  => null,
		'sale_price'     => null,
		'manage_stock'   => false,
		'stock_quantity' => null,
		'stock_status'   => 'instock',
		'tax_status'     => 'taxable',
	);

	if ( empty( $skus ) ) {
		return $simple;
	}

	$sku       = $skus[0];
	$sku_field = isset( $sku->fieldData ) && is_object( $sku->fieldData ) ? $sku->fieldData : null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
	if ( null === $sku_field ) {
		return $simple;
	}

	if ( $this->should_process( 'price' ) ) {
		$prices                  = $this->extract_prices( $sku_field );
		$simple['regular_price'] = $prices['regular_price'];
		$simple['sale_price']    = $prices['sale_price'];
	}

	if ( $this->should_process( 'sku' ) && isset( $sku_field->sku ) ) {
		$simple['sku'] = wc_clean( (string) $sku_field->sku );
	}

	if ( $this->should_process( 'stock' ) ) {
		$stock                    = $this->extract_stock( $sku_field );
		$simple['manage_stock']   = $stock['manage_stock'];
		$simple['stock_quantity'] = $stock['stock_quantity'];
		$simple['stock_status']   = $stock['stock_status'];
	}

	if ( $this->should_process( 'weight' ) ) {
		$simple['weight'] = $this->extract_weight( $sku_field );
	}

	if ( $this->should_process( 'dimensions' ) ) {
		$simple = array_merge( $simple, $this->extract_dimensions( $sku_field ) );
	}

	return $simple;
}