Automattic\WooCommerce\Internal\ProductFeed\Mapping

UcpProductMapper::build_variation_list │ private │ WC 1.0

Hydrate and transform variations in order, stopping at an optional limit.

The limit is applied while iterating rather than by slicing afterwards, so variations past it are never loaded.

Method of the class: UcpProductMapper{}

No Hooks.

Returns

array.

Usage

// private - for code of main (parent) class only
$result = $this->build_variation_list( $variation_ids, $options, $currency, ?int $limit ): array;
$variation_ids(array) (required)
Variation ids, in the order to build them.
$options(array) (required)
Selected options keyed by variation id, from the parent item.
$currency(string) (required)
ISO 4217 currency code.
?int $limit
.
Default: null

UcpProductMapper::build_variation_list() code WC 11.3.0

private function build_variation_list( array $variation_ids, array $options, string $currency, ?int $limit = null ): array {
	$variants = array();

	foreach ( $variation_ids as $variation_id ) {
		if ( null !== $limit && count( $variants ) >= $limit ) {
			break;
		}

		$variation = wc_get_product( $variation_id );
		if ( ! $variation instanceof \WC_Product_Variation ) {
			continue;
		}

		$variants[] = $this->build_variation_variant( $this->item( $variation ), $options[ (int) $variation_id ] ?? array(), $currency );
	}

	return $variants;
}