Skip to content

Google Pull work integration branch. #2981

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

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from

Conversation

budzanowski
Copy link
Collaborator

@budzanowski budzanowski commented Jun 23, 2025

Summary

This PR combines eight related enhancements to improve the Google for WooCommerce integration:

  1. WC REST API Settings Integration (from Add the G4W settings to WC REST API #2821)
  2. Sync Push Control System (from Block Shipping, Products and Coupons when Sync Push is disabled #2810)
  3. WPCOM API Authorization Cleanup (from Remove WPCOM API authorization check as authorization is granted by default #2982)
  4. Google Account Linking Integration (related to Reintroduce account:connect functionality for Google account linking #2976)
  5. WPCOM API Partner Token Health Fix (from Fix WPCOM API partner token validation for client credentials #2985)
  6. Remove Opt-in/Opt-out UI Controls (from Remove opt-in/opt-out UI controls for product data sync #2987)
  7. ✅ Manual Account Linking Endpoint (from Add /wc/gla/connect endpoint for Google-triggered account linking #2977 - COMPLETED)
  8. ✅ Add blog_id to Notification Messages (from Add blog_id to all notification messages (INTEGRA-49) #2989 - COMPLETED)

Changes from PR #2821 - Add the G4W settings to WC REST API

  • Adds /settings/google-for-woocommerce endpoint to WC REST API
  • Moves G4W settings from /settings/general to dedicated group
  • Includes settings: gla_google_connected, gla_jetpack_connected, gla_language, gla_merchant_center, gla_shipping_rates, gla_shipping_times, gla_target_audience
  • Protected by gla_syncable parameter for security
  • Provides proper API structure for external integrations

Changes from PR #2810 - Block Shipping, Products and Coupons when Sync Push is disabled

  • Blocks Merchant Center sync when push sync is disabled for specific data types
  • Prevents scheduled jobs for products, coupons, and shipping when sync is disabled
  • Returns proper error messages when attempting manual sync with disabled push functionality
  • Enhances sync control granularity for better merchant experience

Changes from PR #2982 - Remove WPCOM API authorization check as authorization is granted by default

  • Remove is_wpcom_api_authorized() method from Options and OptionsInterface classes
  • Update NotificationsService to remove redundant authorization checks from business logic
  • Clean up authorization-related fields from error logging and analytics tracking
  • Update unit tests to remove authorization-specific test scenarios
  • Simplifies the codebase by removing unnecessary validation while maintaining robust functionality through other existing checks

Related to PR #2976 - Reintroduce account:connect functionality for Google account linking (merged to develop)

  • Reintroduces the account:connect functionality with blog_id requirement
  • Adds update_sdi_merchant_account() method to Middleware class for Google's SDI account:connect endpoint
  • Integrates into merchant account setup flow with proper error handling
  • Complements the authorization cleanup and API improvements in this PR

Changes from PR #2985 - Fix WPCOM API partner token validation for client credentials (merged)

  • Fixes WPCOM API health checks that were failing after switching from OAuth to client credentials (INTEGRA-48)
  • Injects is_partner_token_healthy: true when WPCOM returns false due to outdated OAuth-based validation
  • Auto-sets WPCOM_REST_API_STATUS to 'approved' by default since authorization is automatic with client credentials
  • Resolves blocked NotificationsService functionality and incorrect UI states
  • Temporary compatibility fix until INTEGRA-50 updates WPCOM API endpoints
  • Preserves code structure for future UI functionality allowing user management of these settings

Changes from PR #2987 - Remove opt-in/opt-out UI controls for product data sync (merged)

  • Removes "Disable product data fetch" button from Merchant Center account card
  • Removes EnableNewProductSyncNotice banner from settings page
  • Removes API_DATA_FETCH_FEATURE option from disconnect modal
  • Preserves EnableNewProductSyncButton for "Grant access" during auth errors
  • Maintains backend API endpoints and both push/pull sync mechanisms
  • Simplifies user experience by removing confusing opt-in/opt-out controls since feature is now enabled by default

✅ Changes from PR #2977 - Add manual account linking endpoint (COMPLETED)

  • NEW: Implements GET /wp-json/wc/gla/connect endpoint for Google-triggered account linking
  • Calls update_sdi_merchant_account() when invoked by Google
  • Returns success response with merchant_center_id and blog_id
  • Uses standard WooCommerce authentication (manage_woocommerce capability)
  • Supports WPCOM proxy authentication via Jetpack tokens
  • Enables Google to manually trigger account linking for special cases or existing merchants

✅ Changes from PR #2989 - Add blog_id to notification messages (COMPLETED)

  • NEW: Adds blog_id property to NotificationsService class
  • Includes blog_id in all notification message bodies sent to WPCOM endpoints
  • Updates NotificationsServiceTest to expect blog_id in request verification
  • Enables WPCOM notification proxy to work with client credentials authentication flow
  • Affects all notification types: products, coupons, shipping, and settings
  • Zero breaking changes - purely additive enhancement that's backward compatible

Test Plan

For WC REST API Settings:

  1. Test fresh install API responses are empty (200)
  2. Test gla_syncable=1 parameter returns all expected settings
  3. Verify settings update during onboarding process
  4. Test settings changes reflect in API responses
  5. Verify shipping settings synchronization

For Sync Push Controls:

  1. Test product/coupon/shipping sync jobs are created when push sync enabled
  2. Test no jobs are scheduled when push sync is disabled
  3. Verify manual sync fails with proper error when push sync disabled
  4. Test granular control for different data types (products, coupons, shipping)

For WPCOM API Authorization Cleanup:

  1. Run unit tests to ensure no regressions: composer test
  2. Verify NotificationService continues to function correctly
  3. Confirm error logging still provides useful debug information
  4. Test that analytics tracking data is still collected properly
  5. Ensure linting passes: composer lint

For Account Linking Integration:

  1. Test merchant center onboarding flow with account:connect functionality
  2. Verify integration with authorization cleanup changes
  3. Test API settings work correctly with account linking flow

For WPCOM API Partner Token Health Fix:

  1. Verify Connection Test page shows 'approved' instead of 'NOT SET'
  2. Confirm NotificationsService.is_ready() returns true
  3. Test that Merchant Center account shows proper connected state
  4. Ensure no "Grant access" buttons appear inappropriately
  5. Verify product sync and notifications work correctly

For UI Controls Removal:

  1. Verify no "Disable product data fetch" button appears in Merchant Center card
  2. Confirm no EnableNewProductSyncNotice banner shows on settings page
  3. Test that disconnect modal no longer has API data fetch option
  4. Ensure sync functionality remains fully operational
  5. Verify API endpoints still work for programmatic control

✅ For Manual Account Linking Endpoint:

  1. ✅ Test endpoint returns 401 for unauthenticated requests
  2. ✅ Verify endpoint calls update_sdi_merchant_account() correctly
  3. ✅ Test response format includes merchant_center_id and blog_id
  4. ✅ Confirm WPCOM proxy authentication works via Jetpack tokens
  5. ✅ Test error handling when merchant ID is not set

✅ For Notification Messages with blog_id:

  1. ✅ Test all notification types include blog_id in message body
  2. ✅ Verify NotificationsServiceTest expects blog_id in request verification
  3. ✅ Confirm backward compatibility - no breaking changes
  4. ✅ Test notification flow works with client credentials authentication
  5. ✅ Verify WPCOM proxy can process blog_id in notification payloads

Related PRs

INTEGRA-30 Project Status

Completed Tasks:

  • ✅ INTEGRA-45: Manual account linking endpoint
  • ✅ INTEGRA-47: Remove opt-in/opt-out UI controls
  • ✅ INTEGRA-48: Fix WPCOM API health checks
  • ✅ INTEGRA-49: Add blog_id to notification messages
  • ✅ INTEGRA-51: Fix is_wpcom_api_authorized logic

Remaining Tasks:

  • 🔄 INTEGRA-46: WPCOM infrastructure (in progress)
  • 🔄 INTEGRA-50: WPCOM endpoint updates (pending)

All PRs are part of the broader INTEGRA-30 effort to improve Google for WooCommerce API integration, sync controls, account linking functionality, client credentials compatibility, and simplified user experience.

🤖 Generated with Claude Code

Copy link

codecov bot commented Jun 23, 2025

Codecov Report

Attention: Patch coverage is 57.14286% with 60 lines in your changes missing coverage. Please review.

Project coverage is 66.2%. Comparing base (7d6c870) to head (1608578).

Files with missing lines Patch % Lines
src/Integration/WPCOMProxy.php 69.1% 17 Missing ⚠️
src/Product/ProductSyncer.php 7.1% 13 Missing ⚠️
src/DB/Query/ShippingRateQuery.php 41.7% 7 Missing ⚠️
src/ConnectionTest.php 0.0% 6 Missing ⚠️
src/Coupon/CouponSyncer.php 64.3% 5 Missing ⚠️
src/Coupon/SyncerHooks.php 50.0% 3 Missing ⚠️
src/Product/SyncerHooks.php 50.0% 3 Missing ⚠️
src/API/Google/Settings.php 0.0% 2 Missing ⚠️
src/MerchantCenter/AccountService.php 60.0% 2 Missing ⚠️
...ependencyManagement/IntegrationServiceProvider.php 0.0% 1 Missing ⚠️
... and 1 more
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             develop   #2981     +/-   ##
===========================================
  Coverage       66.1%   66.2%             
- Complexity      4820    4837     +17     
===========================================
  Files            491     826    +335     
  Lines          20506   25814   +5308     
  Branches           0    1269   +1269     
===========================================
+ Hits           13563   17080   +3517     
- Misses          6943    8581   +1638     
- Partials           0     153    +153     
Flag Coverage Δ
js-unit-tests 66.4% <ø> (?)
php-unit-tests 66.1% <57.1%> (-<0.1%) ⬇️

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

Files with missing lines Coverage Δ
src/API/WP/NotificationsService.php 97.9% <100.0%> (+3.5%) ⬆️
src/DB/Query/ShippingTimeQuery.php 41.2% <ø> (ø)
src/Jobs/AbstractProductSyncerBatchedJob.php 100.0% <100.0%> (ø)
src/Jobs/AbstractProductSyncerJob.php 100.0% <100.0%> (ø)
src/Jobs/UpdateShippingSettings.php 100.0% <100.0%> (ø)
src/MerchantCenter/MerchantCenterService.php 91.5% <100.0%> (-1.3%) ⬇️
src/Options/Options.php 64.7% <ø> (+2.4%) ⬆️
src/Shipping/SyncerHooks.php 100.0% <100.0%> (ø)
src/Tracking/TrackerSnapshot.php 0.0% <ø> (ø)
...ependencyManagement/IntegrationServiceProvider.php 0.0% <0.0%> (ø)
... and 10 more

... and 338 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@budzanowski budzanowski changed the title Combined: WC REST API Settings + Sync Push Controls Google Pull work integration branch. Jun 25, 2025
@budzanowski budzanowski force-pushed the test/combined-branches branch from e90ffa7 to 683dc35 Compare June 25, 2025 09:39
puntope and others added 24 commits June 26, 2025 16:14
Update SyncerHooks tests to mock the is_enabled_for_datatype method
that was added to prevent sync jobs when PUSH is disabled. The tests
now properly expect sync operations to be scheduled or not based on
the merchant center status.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
to preserve theJSON type when empty
tomalec and others added 21 commits June 26, 2025 16:14
…y default

Authorization is now granted by default, making the WPCOM API authorization check redundant.

Changes:
- Remove `is_wpcom_api_authorized()` method from Options and OptionsInterface
- Update NotificationsService to remove authorization checks from `is_ready()` method
- Remove authorization status from error logging and debug output
- Remove authorization field from analytics tracking data
- Update unit tests to remove authorization-related test scenarios

The remaining validation in NotificationsService ensures robust functionality through:
- Feature enablement check
- Merchant Center readiness validation
- WordPress.com API health verification
- Data type-specific sync settings

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Remove outdated @param  and fix return type annotation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Fix partner token health check in is_wpcom_api_status_healthy()
  - Inject is_partner_token_healthy: true when WPCOM returns false
  - Preserves existing logic for future compatibility

- Auto-set WPCOM_REST_API_STATUS to 'approved' in get_connected_status()
  - Set status to 'approved' by default when not set
  - Preserves code structure for future UI functionality

These changes fix issues after switching from OAuth to client credentials
in INTEGRA-48, ensuring the system works properly with the new auth method.

Addresses: INTEGRA-51

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Mock is_wpcom_api_status_healthy to return true in test_get_connected_status_incomplete
- Update expected wpcom_rest_api_status to 'approved' instead of null
- Reflects new behavior where authorization is always approved with client credentials

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Removes user-facing controls for enabling/disabling the new product sync feature since it's now enabled by default with client credentials.

## Changes Made

### Removed UI Components:
- "Disable product data fetch" button from Merchant Center account card
- EnableNewProductSyncNotice banner from settings page
- API_DATA_FETCH_FEATURE option from disconnect modal

### Preserved Functionality:
- EnableNewProductSyncButton for "Grant access" during auth errors
- Backend API endpoints for sync control
- Both push and pull sync mechanisms
- API-based configuration control

## Impact

- Clean UI without confusing opt-in/opt-out controls
- Sync functionality remains fully operational
- Feature enabled by default with client credentials
- API control still available for developers

Addresses: INTEGRA-47

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Auto-fix JavaScript formatting issue identified by eslint/prettier.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@budzanowski budzanowski force-pushed the test/combined-branches branch from bbff78a to e5982a4 Compare June 26, 2025 14:16
budzanowski and others added 2 commits June 27, 2025 05:36
- Add blog_id property to NotificationsService class
- Include blog_id in all notification message bodies sent to WPCOM
- Update NotificationsServiceTest to expect blog_id in request body
- Enables WPCOM notification proxy to work with client credentials flow

This change ensures all notification messages include the WordPress.com
blog_id in their payload, which is required for the WPCOM proxy system
to properly route notifications in the new client credentials
authentication flow.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…-id-to-notifications

Add blog_id to all notification messages (INTEGRA-49)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants