Skip to content
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

Add Shipping notifications #2252

Merged
merged 6 commits into from
Feb 14, 2024

Conversation

puntope
Copy link
Contributor

@puntope puntope commented Feb 8, 2024

Changes proposed in this Pull Request:

This PR implement Notifications for Shipping Updates.
As discussed for now we don't send Item IDs and just send a generic "shipping.update" method with no Item ID

Detailed test instructions:

  1. Checkout this PR, complete onboarding and select "Shipping Rates --> Automatically sync my store’s shipping settings to Google."
  2. Go to WooCommerce -- Settings -- Shipping and update something
  3. See the Job gla/jobs/notifications/shipping/process_item appearing
  4. Run it and see the notification shipping.update happening

Additional details:

⚠️ The topic needs to be enabled in the Proxy, so all the notifications will fail

Changelog entry

@puntope puntope requested a review from a team February 8, 2024 19:59
@puntope puntope self-assigned this Feb 8, 2024
@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Feb 8, 2024
@puntope puntope marked this pull request as ready for review February 8, 2024 20:10
Copy link
Contributor

@jorgemd24 jorgemd24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @puntope for adding this new notification. I left a couple of minor comments about the code.

As discussed for now we don't send Item IDs and just send a generic "shipping.update" method with no Item ID

Can you point me to that discussion? What I see is that without that ID, Google would have to make multiple requests to figure out which Shipping Zone has been modified.

When I send a request to wc/v3/shipping/zones, it only gives me the Shipping Zone name without details about the shipping zone methods. So, if a shipping zone method gets updated, Google would have to make separate calls to wc/v3/shipping/zones/ZONE_ID/methods for each zone.

Additionally, what do you think in adding tests for the ShippingNotification Job?

I'm guessing there'll be a follow-up PR for create/delete notifications, is that correct?

* @param int $item_id
* @param string $topic
* @param string $topic The topic to use in the notification.
* @param int|null $item_id Tme item ID to notify. It can be null for topics that doesn't need Item ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo Tme -> The

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here 72f00f8

/**
* @var NotificationsService $notifications_service
*/
protected $notifiations_service;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: $notifiations_service -> $notifications_service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here 72f00f8

@@ -128,7 +143,13 @@ protected function handle_update_shipping_settings() {
if ( $this->already_scheduled ) {
return;
}
$this->update_shipping_job->schedule();

if ( $this->notifiations_service->is_enabled() ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT if we also add this checking in the method can_schedule()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted here 34e1329

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 35 lines in your changes are missing coverage. Please review.

Comparison is base (2605d10) 58.8% compared to head (a98ca65) 59.0%.
Report is 63 commits behind head on feature/google-api-project.

Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##             feature/google-api-project   #2252     +/-   ##
==============================================================
+ Coverage                          58.8%   59.0%   +0.3%     
- Complexity                         4249    4276     +27     
==============================================================
  Files                               458     460      +2     
  Lines                             16902   18041   +1139     
==============================================================
+ Hits                               9935   10653    +718     
- Misses                             6967    7388    +421     
Flag Coverage Δ
php-unit-tests 59.0% <74.5%> (+0.3%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
google-listings-and-ads.php 75.0% <ø> (+67.3%) ⬆️
src/API/Google/AdsCampaign.php 97.4% <100.0%> (+<0.1%) ⬆️
...rc/API/Site/Controllers/Ads/CampaignController.php 100.0% <100.0%> (ø)
...I/Site/Controllers/Ads/SetupCompleteController.php 94.1% <100.0%> (+5.9%) ⬆️
...trollers/MerchantCenter/SettingsSyncController.php 96.2% <100.0%> (+6.2%) ⬆️
src/Exception/WPErrorTrait.php 58.3% <100.0%> (+41.7%) ⬆️
src/Google/NotificationsService.php 87.5% <100.0%> (+2.1%) ⬆️
...ernal/DependencyManagement/RESTServiceProvider.php 100.0% <100.0%> (ø)
src/Jobs/Notifications/ProductNotificationJob.php 100.0% <100.0%> (+3.3%) ⬆️
src/Jobs/Notifications/ShippingNotificationJob.php 100.0% <100.0%> (ø)
... and 10 more

... and 198 files with indirect coverage changes

@puntope
Copy link
Contributor Author

puntope commented Feb 12, 2024

Additionally, what do you think in adding tests for the ShippingNotification Job?

Added here a98ca65

@puntope
Copy link
Contributor Author

puntope commented Feb 12, 2024

Can you point me to that discussion? What I see is that without that ID, Google would have to make multiple requests to figure out which Shipping Zone has been modified.

This was discussed in the dev call as we decided to operate on ourselves and wait to google for feedback. (instead of asking Google what to do beforehand). In my 1:1 with Mik we decided to just send shipping.update and rely on Google to fetch all the shipping and all the methods by themselves.

I will open a thread in P2 to discuss further. We can add them in future PRs

I created tho some example PR with that approach. #2256
However, it comes with more questions like:

  • Shall we also add notifications for methods?
  • How do we handle shipping class updates?
  • Do we support more options than flat or free shipping?

I suggest to go for now with this PR and discuss further in P2. I will create the discussion tomorrow.

Copy link
Contributor

@jorgemd24 jorgemd24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @puntope for the adjustments and the tests.

However, it comes with more questions like:
Shall we also add notifications for methods?
How do we handle shipping class updates?
Do we support more options than flat or free shipping?

I feel like we should at least include the Shipping Zone ID to avoid unnecessary requests. I don't really see the need to add notifications for methods or the shipping class. For instance, if I query wc/v3/shipping/zones/ZONE_ID/methods, I can retrieve all the methods for that zone ID, making it easier to tell which method has changed.

I suggest to go for now with this PR and discuss further in P2. I will create the discussion tomorrow.

Okay let's do that!

@puntope puntope merged commit 44753b0 into feature/google-api-project Feb 14, 2024
11 checks passed
@puntope puntope deleted the add/shipping-notifications branch February 14, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants