Automattic\WooCommerce\Admin\Features\Fulfillments\DataStore

FulfillmentsDataStore::validate_items │ private │ WC 1.0

Method to validate the items in a fulfillment.

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

Хуков нет.

Возвращает

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

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

// private - только в коде основоного (родительского) класса
$result = $this->validate_items( $data ): void;
$data(Fulfillment) (обязательный)
The fulfillment object to validate.

Код FulfillmentsDataStore::validate_items() WC 11.1.2

private function validate_items( Fulfillment $data ): void {
	$items = $data->get_meta( '_items', true );
	if ( empty( $items ) ) {
		throw new \Exception( esc_html__( 'The fulfillment should contain at least one item.', 'woocommerce' ) );
	}

	if ( ! is_array( $items ) ) {
		throw new \Exception( esc_html__( 'The fulfillment items should be an array.', 'woocommerce' ) );
	}

	foreach ( $data->get_items() as $item ) {
		if ( ! isset( $item['item_id'] )
			// The item ID and qty should be set.
			|| ! isset( $item['qty'] )
			// The item ID should be integers.
			|| ! is_int( $item['item_id'] )
			// Allow the qty to be a float too.
			|| ( ! is_int( $item['qty'] ) && ! is_float( $item['qty'] ) )
			// The item ID and qty should be greater than 0.
			|| $item['item_id'] <= 0
			|| $item['qty'] <= 0
			) {
			throw new \Exception( esc_html__( 'Invalid item.', 'woocommerce' ) );
		}
	}
}