Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldsSchema

DocumentObject::get_cart_dataprotectedWC 1.0

Gets a subset of cart data.

Метод класса: DocumentObject{}

Хуков нет.

Возвращает

Массив. The cart data.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_cart_data();

Код DocumentObject::get_cart_data() WC 10.3.6

protected function get_cart_data() {
	$cart_data               = StoreApi::container()->get( SchemaController::class )->get( CartSchema::IDENTIFIER )->get_item_response( $this->cart );
	$selected_shipping_rates = array_filter(
		array_map(
			function ( $package ) {
				$selected_rate = array_search( true, array_column( $package['shipping_rates'], 'selected' ), true );
				return false !== $selected_rate && isset( $package['shipping_rates'][ $selected_rate ] ) ? $package['shipping_rates'][ $selected_rate ] : null;
			},
			$cart_data['shipping_rates']
		)
	);
	$local_pickup_method_ids = LocalPickupUtils::get_local_pickup_method_ids();

	return wp_parse_args(
		$this->request_data['cart'] ?? [],
		[
			'coupons'            => array_values( wc_list_pluck( $cart_data['coupons'], 'code' ) ),
			'shipping_rates'     => array_values( wc_list_pluck( $selected_shipping_rates, 'rate_id' ) ),
			'items'              => array_merge(
				...array_map(
					function ( $item ) {
						return array_fill( 0, (int) NumberUtil::ceil( $item['quantity'] ), $item['id'] );
					},
					$cart_data['items']
				)
			),
			'items_type'         => array_unique( array_values( wc_list_pluck( $cart_data['items'], 'type' ) ) ),
			'items_count'        => $cart_data['items_count'],
			'items_weight'       => $cart_data['items_weight'],
			'needs_shipping'     => $cart_data['needs_shipping'],
			'prefers_collection' => count( array_intersect( $local_pickup_method_ids, wc_list_pluck( $selected_shipping_rates, 'method_id' ) ) ) > 0,
			'totals'             => [
				'total_price' => (int) $cart_data['totals']->total_price,
				'total_tax'   => (int) $cart_data['totals']->total_tax,
			],
			'extensions'         => (object) $cart_data['extensions'],
		]
	);
}