Skip to content

Commit

Permalink
Get product with status trash for find_delete_product_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlin committed Nov 15, 2022
1 parent 7dfd462 commit 3f7a2cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Product/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
}

Expand Down
8 changes: 6 additions & 2 deletions tests/Unit/Product/ProductRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
);
}
Expand Down

0 comments on commit 3f7a2cc

Please sign in to comment.