-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement RequestReview in the Merchant class #2411
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2411 +/- ##
===========================================
Coverage 64.5% 64.5%
- Complexity 4252 4255 +3
===========================================
Files 458 459 +1
Lines 18041 16790 -1251
===========================================
- Hits 11634 10835 -799
+ Misses 6407 5955 -452
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, it tested well locally, I've left some comments that we could discuss about.
I also found there was a PHP Notice while requesting to GET /gla/mc/review
:
Indirect modification of overloaded element of Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\S ervice\ShoppingContent\FreeListingsProgramStatusRegionStatus has no effect in /var/www/html/wp-content/plugins/google-listings-and-ads/src/Google/RequestReviewStatuses.php on line 136"
The warning seems to be in src/Google/RequestReviewStatuses.php:136, a quick Google search suggests that we could create a copy of $region_status['regoinCodes']
before sorting the array in-place and it worked on my end. But what I don't understand is why this PR would have this warning but without this PR it's all good.
@@ -251,14 +254,91 @@ private function get_cached_review_status(): ?array { | |||
* @throws Exception If the get_account_review_status API call fails. | |||
*/ | |||
private function get_review_status(): ?array { | |||
$review_status = $this->get_cached_review_status(); | |||
$review_status = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Are we no longer using the transient? If that's the case, we could probably remove the get_cached_review_status
and set_cached_review_status
methods as well. But IMO we should continue using the transient as we did before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do_action( 'woocommerce_gla_invalid_response', $response, __METHOD__ ); | ||
$error = $response['message'] ?? __( 'Invalid response getting account review status', 'google-listings-and-ads' ); | ||
throw new Exception( $error, $response->getCode() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if this code would ever be executed. In this PR, the merchant->get_account_review_status()
method returns an array of responses for the statuses of freeListingsProgram and shoppingAdsProgram. If an error occurs, it throws an exception. So I believe lines 288 to 290 would never be reached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats right. I tweaked it here.
/** @var array| Exception $response */ | ||
$response = $this->merchant->get_account_review_status(); | ||
|
||
if ( isset( $response['freeListingsProgram'] ) || isset( $response['shoppingAdsProgram'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using &&
instead of ||
as it will always include both of them in the response? Moreover, what about checking the response status code for both $response['freeListingsProgram']
and $response['shoppingAdsProgram']
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_account_review_status
returns an array with both freeListingsProgram
and shoppingAdsProgram
we don't need both of them as we merge them afterwards in RequestReviewStatuses::get_statuses_from_response()
Regarding the status, the Google call will return FreeListingsProgramStatus
or ShoppingAdsProgramStatus
which is a Collection and doesn't contain statuses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense, thanks for clarifying.
Thanks @ianlin Adjusted here c9078bd
Notice the response we got before via WCS has a JSON encode/decode process making a copy of those arrays. In the current implementation we operate with the response directly. I would bet that may be the reason. |
Hi @ianlin Thanks for your great review and for catching those issues. THis is ready for a new round. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the prompt update, all good. 👍
|
||
/** | ||
* Get the review status for an MC account | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's a new method in this class maybe we could add since x.x.x
.
|
||
/** | ||
* Request a review for an MC account | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for adding since x.x.x
.
Changes proposed in this Pull Request:
This PR implementers Get Account Review Status and Request a Review in the MErchant Class instead of doing it with WooCommerce Connect Server (via Middleware)
The reason of this is in order to avoid unnecessary manager quota requests
See slack context here: p1713778408402949-slack-C02BB3F30TG
Screenshots:
Screen.Recording.2024-05-24.at.20.23.49.mov
Detailed test instructions:
Additional details:
Changelog entry