Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::read_multiple()publicWC 6.9.0

Reads multiple orders from custom tables in one pass.

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

Хуки из метода

Возвращает

null. Ничего (null).

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

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->read_multiple( $orders );
$orders(array[\WC_Order]) (обязательный) (передается по ссылке — &)
Order objects.

Список изменений

С версии 6.9.0 Введена.

Код OrdersTableDataStore::read_multiple() WC 8.7.0

public function read_multiple( &$orders ) {
	$order_ids = array_keys( $orders );
	$data      = $this->get_order_data_for_ids( $order_ids );

	if ( count( $data ) !== count( $order_ids ) ) {
		throw new \Exception( __( 'Invalid order IDs in call to read_multiple()', 'woocommerce' ) );
	}

	$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
	if ( ! $data_synchronizer instanceof DataSynchronizer ) {
		return;
	}

	$data_sync_enabled = $data_synchronizer->data_sync_is_enabled();
	if ( $data_sync_enabled ) {
		/**
		 * Allow opportunity to disable sync on read, while keeping sync on write enabled. This adds another step as a large shop progresses from full sync to no sync with HPOS authoritative.
		 * This filter is only executed if data sync is enabled from settings in the first place as it's meant to be a step between full sync -> no sync, rather than be a control for enabling just the sync on read. Sync on read without sync on write is problematic as any update will reset on the next read, but sync on write without sync on read is fine.
		 *
		 * @param bool $read_on_sync_enabled Whether to sync on read.
		 *
		 * @since 8.1.0
		 */
		$data_sync_enabled = apply_filters( 'woocommerce_hpos_enable_sync_on_read', $data_sync_enabled );
	}

	$load_posts_for = array_diff( $order_ids, array_merge( self::$reading_order_ids, self::$backfilling_order_ids ) );
	$post_orders    = $data_sync_enabled ? $this->get_post_orders_for_ids( array_intersect_key( $orders, array_flip( $load_posts_for ) ) ) : array();

	foreach ( $data as $order_data ) {
		$order_id = absint( $order_data->id );
		$order    = $orders[ $order_id ];

		$this->init_order_record( $order, $order_id, $order_data );

		if ( $data_sync_enabled && $this->should_sync_order( $order ) && isset( $post_orders[ $order_id ] ) ) {
			self::$reading_order_ids[] = $order_id;
			$this->maybe_sync_order( $order, $post_orders[ $order->get_id() ] );
		}
	}
}