Skip to content

Commit

Permalink
Merge branch 'feature/refactor-product-stats' into add/merchant-cente…
Browse files Browse the repository at this point in the history
…r-report-test
  • Loading branch information
jorgemd24 committed Feb 20, 2024
2 parents 19b4db5 + fbcd45c commit 71e2c3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Product/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function find_ids( array $args = [], int $limit = -1, int $offset = 0 ):
* @return WC_Product[] Array of WooCommerce product objects
*/
public function find_by_ids( array $ids, array $args = [], int $limit = -1, int $offset = 0 ): array {
// If no product IDs are supplied then return early to avoid querying and loading every product.
if ( empty( $ids ) ) {
return [];
}

$args['include'] = $ids;

return $this->find( $args, $limit, $offset );
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Product/ProductRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public function test_find_by_ids() {
array_map( 'wc_get_product', $ids ),
$this->product_repository->find_by_ids( $ids )
);

$this->assertEquals( [], $this->product_repository->find_by_ids( [] ) );
}

public function test_find_synced_products() {
Expand Down

0 comments on commit 71e2c3d

Please sign in to comment.