diff --git a/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedGenerator.php b/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedGenerator.php index 3147ff25b..82707f3c6 100644 --- a/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedGenerator.php +++ b/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedGenerator.php @@ -37,9 +37,11 @@ protected function get_items_for_batch( int $batch_number, array $args ): array $offset = ( $batch_number - 1 ) * $batch_size; $query_args = array( - 'number' => $batch_size, - 'offset' => $offset, - 'status' => 'approve', + 'number' => $batch_size, + 'offset' => $offset, + 'status' => 'approve', + 'post_type' => 'product', + 'comment_type' => 'review', ); return FeedUploadUtils::get_ratings_and_reviews_data( $query_args ); diff --git a/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedHandler.php b/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedHandler.php index 7342d7728..8fbf7fe9e 100644 --- a/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedHandler.php +++ b/includes/Feed/RatingsAndReviews/RatingsAndReviewsFeedHandler.php @@ -39,7 +39,9 @@ public function __construct( AbstractFeedFileWriter $feed_writer ) { */ public function get_feed_data(): array { $query_args = array( - 'status' => 'approve', + 'status' => 'approve', + 'post_type' => 'product', + 'comment_type' => 'review', ); return FeedUploadUtils::get_ratings_and_reviews_data( $query_args ); diff --git a/tests/Unit/Feed/FeedUploadUtilsTest.php b/tests/Unit/Feed/FeedUploadUtilsTest.php index f380104e9..d06be7077 100644 --- a/tests/Unit/Feed/FeedUploadUtilsTest.php +++ b/tests/Unit/Feed/FeedUploadUtilsTest.php @@ -29,6 +29,7 @@ public function test_get_ratings_and_reviews_data_valid_review() { // Create a review comment. $comment_id = self::factory()->comment->create( [ 'comment_post_ID' => $product_id, + 'comment_type' => 'review', 'comment_date' => '2023-10-01 10:00:00', 'comment_content' => 'Awesome product!', 'comment_author' => 'John Doe', @@ -36,7 +37,14 @@ public function test_get_ratings_and_reviews_data_valid_review() { ] ); update_comment_meta( $comment_id, 'rating', 5 ); - $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] ); + //Query arguments to fetch R&R data + $query_args = array( + 'status' => 'approve', + 'post_type' => 'product', + 'comment_type' => 'review', + ); + + $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args ); $expected_review = [ 'aggregator' => 'woocommerce', @@ -83,7 +91,14 @@ public function test_get_ratings_and_reviews_data_non_product_review() { ] ); update_comment_meta( $comment_id, 'rating', 4 ); - $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] ); + //Query arguments to fetch R&R data + $query_args = array( + 'status' => 'approve', + 'post_type' => 'product', + 'comment_type' => 'review', + ); + + $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args ); $this->assertEmpty( $result, 'Expected no review for a non-product comment.' ); } @@ -100,13 +115,21 @@ public function test_get_ratings_and_reviews_data_no_rating_review() { // Create a comment without a valid rating. $comment_id = self::factory()->comment->create( [ 'comment_post_ID' => $product_id, + 'comment_type' => 'review', 'comment_date' => '2023-10-01 10:00:00', 'comment_content' => 'I did not rate this product.', 'comment_author' => 'Alice', 'user_id' => 3, ] ); - $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] ); + //Query arguments to fetch R&R data + $query_args = array( + 'status' => 'approve', + 'post_type' => 'product', + 'comment_type' => 'review', + ); + + $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args ); $this->assertEmpty( $result, 'Expected no review when rating is missing.' ); } @@ -115,6 +138,7 @@ public function test_get_ratings_and_reviews_data_invalid_product() { $invalid_product_id = 999999; $comment_id = self::factory()->comment->create( [ 'comment_post_ID' => $invalid_product_id, + 'comment_type' => 'review', 'comment_date' => '2023-10-01 12:00:00', 'comment_content' => 'Product does not exist.', 'comment_author' => 'Bob', @@ -122,7 +146,14 @@ public function test_get_ratings_and_reviews_data_invalid_product() { ] ); update_comment_meta( $comment_id, 'rating', 3 ); - $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( [] ); + //Query arguments to fetch R&R data + $query_args = array( + 'status' => 'approve', + 'post_type' => 'product', + 'comment_type' => 'review', + ); + + $result = \WooCommerce\Facebook\Feed\FeedUploadUtils::get_ratings_and_reviews_data( $query_args ); $this->assertEmpty( $result, 'Expected no review for comment with invalid product.' ); } @@ -168,7 +199,7 @@ public function test_get_coupons_data_valid_coupon_with_target_product() { // Build the expected coupon shape according to how FeedUploadUtils outputs the data. $expected_coupon = [ 'offer_id' => $coupon_id, // coupon ID as an integer - 'title' => 'coupon-code-1', // lowercased coupon post title + 'title' => 'COUPON-CODE-1', // uppercase coupon post title 'value_type' => 'PERCENTAGE', 'percent_off' => '15', // as a string 'fixed_amount_off' => '', // empty string output @@ -178,7 +209,7 @@ public function test_get_coupons_data_valid_coupon_with_target_product() { 'target_selection' => 'SPECIFIC_PRODUCTS', 'start_date_time' => $coupon_data['start_date_time'], // use the output from the coupon post date/time 'end_date_time' => '', - 'coupon_codes' => ['coupon-code-1'], + 'coupon_codes' => ['COUPON-CODE-1'], 'public_coupon_code' => '', 'target_filter' => '{"or":[{"retailer_id":{"eq":"product-sku-1_'.$product1->get_id().'"}}]}', 'target_product_retailer_ids' => '', @@ -234,7 +265,7 @@ public function test_get_coupons_data_valid_shipping_coupon() { // Build the expected coupon shape according to how FeedUploadUtils outputs the data. $expected_coupon = [ 'offer_id' => $coupon_id, // coupon ID as an integer - 'title' => 'coupon-code-1', // lowercased coupon post title + 'title' => 'COUPON-CODE-1', // uppercase coupon post title 'value_type' => 'PERCENTAGE', 'fixed_amount_off' => '0', // empty string output 'percent_off' => '100', // as a string @@ -244,7 +275,7 @@ public function test_get_coupons_data_valid_shipping_coupon() { 'target_selection' => 'ALL_CATALOG_PRODUCTS', 'start_date_time' => $coupon_data['start_date_time'], // use the output from the coupon post date/time 'end_date_time' => '', - 'coupon_codes' => ['coupon-code-1'], + 'coupon_codes' => ['COUPON-CODE-1'], 'public_coupon_code' => '', 'target_filter' => '', 'target_product_retailer_ids' => '', @@ -326,7 +357,7 @@ public function test_get_coupons_data_coupon_with_included_excluded_products() { // Build the expected coupon shape. $expected_coupon = [ 'offer_id' => $coupon_id, // coupon ID as an integer - 'title' => 'coupon-incl-excl', // lowercased coupon post title + 'title' => 'COUPON-INCL-EXCL', // uppercase coupon post title 'value_type' => 'PERCENTAGE', 'percent_off' => '20', // as a string 'fixed_amount_off' => '', // empty string output @@ -336,7 +367,7 @@ public function test_get_coupons_data_coupon_with_included_excluded_products() { 'target_selection' => 'SPECIFIC_PRODUCTS', 'start_date_time' => $coupon_data['start_date_time'], // use the generated start date/time 'end_date_time' => '', - 'coupon_codes' => ['coupon-incl-excl'], // coupon_codes as an array containing the title + 'coupon_codes' => ['COUPON-INCL-EXCL'], // coupon_codes as an array containing the title 'public_coupon_code' => '', 'target_filter' => '{"and":[{"or":[{"retailer_id":{"eq":"product-sku-1_'.$product1->get_id().'"}},{"retailer_id":{"eq":"product-sku-2_'.$product2->get_id().'"}}]},{"and":[{"retailer_id":{"neq":"product-sku-3_'.$product3->get_id().'"}}]}]}', 'target_product_retailer_ids' => '', @@ -435,8 +466,8 @@ public function test_get_coupons_data_coupon_with_included_excluded_categories() // Build the expected coupon shape. $expected_coupon = [ - 'offer_id' => $coupon_id, // coupon ID as an integer - 'title' => 'coupon-cat-only', // lowercased coupon post title + 'offer_id' => $coupon_id, // coupon ID as an integer + 'title' => 'COUPON-CAT-ONLY', // uppercase coupon post title 'value_type' => 'PERCENTAGE', 'percent_off' => '15', // as a string 'fixed_amount_off' => '', // empty string output @@ -446,7 +477,7 @@ public function test_get_coupons_data_coupon_with_included_excluded_categories() 'target_selection' => 'SPECIFIC_PRODUCTS', 'start_date_time' => $coupon_data['start_date_time'], // generated start date/time 'end_date_time' => '', - 'coupon_codes' => ['coupon-cat-only'], // coupon_codes as an array containing the code + 'coupon_codes' => ['COUPON-CAT-ONLY'], // coupon_codes as an array containing the code 'public_coupon_code' => '', 'target_filter' => $expected_target_filter, 'target_product_retailer_ids' => '',