Merge branch 'add/49335-related-products-collection' into add/50860-upsells
This commit is contained in:
commit
99dff53412
|
@ -990,6 +990,11 @@ class ProductCollection extends AbstractBlock {
|
||||||
// has otherwise excluded from the results.
|
// has otherwise excluded from the results.
|
||||||
if ( count( $post__in ) > 1 ) {
|
if ( count( $post__in ) > 1 ) {
|
||||||
$post__in = array_intersect( ...$post__in );
|
$post__in = array_intersect( ...$post__in );
|
||||||
|
// An empty array means that there was no overlap between the filters and so
|
||||||
|
// the query should return no results.
|
||||||
|
if ( empty( $post__in ) ) {
|
||||||
|
return array( -1 );
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$post__in = reset( $post__in );
|
$post__in = reset( $post__in );
|
||||||
}
|
}
|
||||||
|
|
|
@ -975,7 +975,7 @@ class ProductCollection extends \WP_UnitTestCase {
|
||||||
/**
|
/**
|
||||||
* Test merging exclusive id filters.
|
* Test merging exclusive id filters.
|
||||||
*/
|
*/
|
||||||
public function test_merges_exclusive_id_filters() {
|
public function test_merges_post__in() {
|
||||||
$existing_id_filter = array( 1, 4 );
|
$existing_id_filter = array( 1, 4 );
|
||||||
$handpicked_product_ids = array( 3, 4, 5, 6 );
|
$handpicked_product_ids = array( 3, 4, 5, 6 );
|
||||||
// The only ID present in ALL of the exclusive filters is 4.
|
// The only ID present in ALL of the exclusive filters is 4.
|
||||||
|
@ -994,6 +994,22 @@ class ProductCollection extends \WP_UnitTestCase {
|
||||||
$this->assertCount( 1, $merged_query['post__in'] );
|
$this->assertCount( 1, $merged_query['post__in'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test merging exclusive id filters with no intersection.
|
||||||
|
*/
|
||||||
|
public function test_merges_post__in_empty_result_without_intersection() {
|
||||||
|
$existing_id_filter = array( 1, 4 );
|
||||||
|
$handpicked_product_ids = array( 2, 3 );
|
||||||
|
|
||||||
|
$parsed_block = $this->get_base_parsed_block();
|
||||||
|
$parsed_block['attrs']['query']['post__in'] = $existing_id_filter;
|
||||||
|
$parsed_block['attrs']['query']['woocommerceHandPickedProducts'] = $handpicked_product_ids;
|
||||||
|
|
||||||
|
$merged_query = $this->initialize_merged_query( $parsed_block );
|
||||||
|
|
||||||
|
$this->assertEquals( array( -1 ), $merged_query['post__in'] );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for frontend collection handlers.
|
* Test for frontend collection handlers.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue