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

WebflowMapper::extract_stockprivateWC 1.0

Map Webflow inventory shape to WC stock fields.

Method of the class: WebflowMapper{}

No Hooks.

Returns

Array{manage_stock:. bool, stock_quantity: ?int, stock_status: string}

Usage

// private - for code of main (parent) class only
$result = $this->extract_stock( $sku_field ): array;
$sku_field(object) (required)
SKU fieldData.

WebflowMapper::extract_stock() code WC 11.0.0

private function extract_stock( object $sku_field ): array {
	$inventory = isset( $sku_field->inventory ) && is_object( $sku_field->inventory ) ? $sku_field->inventory : null;

	if ( null === $inventory ) {
		return array(
			'manage_stock'   => false,
			'stock_quantity' => null,
			'stock_status'   => 'instock',
		);
	}

	$type = isset( $inventory->type ) ? (string) $inventory->type : 'infinite';
	if ( 'finite' !== $type ) {
		return array(
			'manage_stock'   => false,
			'stock_quantity' => null,
			'stock_status'   => 'instock',
		);
	}

	$quantity = isset( $inventory->quantity ) ? (int) $inventory->quantity : 0;
	return array(
		'manage_stock'   => true,
		'stock_quantity' => $quantity,
		'stock_status'   => $quantity > 0 ? 'instock' : 'outofstock',
	);
}