From 3f7a2cc889c87b7c95266df073b8db1de15abed3 Mon Sep 17 00:00:00 2001 From: Ian Yu-Hsun Lin Date: Tue, 15 Nov 2022 14:46:38 +0800 Subject: [PATCH] Get product with status `trash` for `find_delete_product_ids` --- src/Product/ProductRepository.php | 6 ++++-- tests/Unit/Product/ProductRepositoryTest.php | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Product/ProductRepository.php b/src/Product/ProductRepository.php index d8896818b4..58fd75543b 100644 --- a/src/Product/ProductRepository.php +++ b/src/Product/ProductRepository.php @@ -81,12 +81,13 @@ public function find_ids( array $args = [], int $limit = -1, int $offset = 0 ): * Find and return an array of WooCommerce product objects based on the provided product IDs. * * @param int[] $ids Array of WooCommerce product IDs + * @param array $args Array of WooCommerce args (except 'return'), and product metadata. * @param int $limit Maximum number of results to retrieve or -1 for unlimited. * @param int $offset Amount to offset product results. * * @return WC_Product[] Array of WooCommerce product objects */ - public function find_by_ids( array $ids, int $limit = -1, int $offset = 0 ): array { + public function find_by_ids( array $ids, array $args = [], int $limit = -1, int $offset = 0 ): array { $args['include'] = $ids; return $this->find( $args, $limit, $offset ); @@ -163,7 +164,8 @@ public function find_sync_ready_products( array $args = [], int $limit = - 1, in * @return array */ public function find_delete_product_ids( array $ids, int $limit = - 1, int $offset = 0 ): array { - $results = $this->find_by_ids( $ids, $limit, $offset ); + $args = [ 'status' => 'trash' ]; + $results = $this->find_by_ids( $ids, $args, $limit, $offset ); return $this->product_filter->filter_products_for_delete( $results )->get_product_ids(); } diff --git a/tests/Unit/Product/ProductRepositoryTest.php b/tests/Unit/Product/ProductRepositoryTest.php index 202bac991e..dd30d5eae4 100644 --- a/tests/Unit/Product/ProductRepositoryTest.php +++ b/tests/Unit/Product/ProductRepositoryTest.php @@ -309,10 +309,14 @@ public function test_find_delete_product_ids() { $this->product_helper->mark_as_synced( $product_2, $this->generate_google_product_mock() ); $this->product_meta->update_failed_delete_attempts( $product_2, 5 ); - $ids = [ $product_1->get_id(), $product_2->get_id() ]; + // A trashed product that is marked as not_synced in SyncStatus. + $product_3 = WC_Helper_Product::create_simple_product( true, [ 'status' => 'trash' ] ); + $this->product_helper->mark_as_unsynced( $product_3 ); + + $ids = [ $product_1->get_id(), $product_2->get_id(), $product_3->get_id() ]; $this->assertEquals( - [ $product_1->get_id() ], + [ $product_3->get_id() ], $this->product_repository->find_delete_product_ids( $ids ) ); }