-
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
Get product stats using the Merchant Center report query #2229
Merged
jorgemd24
merged 147 commits into
feature/refactor-product-stats
from
add/product-view-report-query
Feb 8, 2024
Merged
Changes from all commits
Commits
Show all changes
147 commits
Select commit
Hold shift + click to select a range
25db819
WIP
jorgemd24 81918f5
Add Missing Jetpack functions
jorgemd24 05ab472
Add JetpackWPCOM to the service provider
jorgemd24 6975f77
Move out initial code of GoogleListingsAndAdsPlugin file
jorgemd24 1f7ca4c
Added links to the Jetpack functions and remove duplicated PHPDoc
jorgemd24 021017b
Merge pull request #2145 from woocommerce/add/missing-functions-jetpa…
jorgemd24 b4130fe
Filter results for WC Proxy
jorgemd24 ebe9798
WIP tests
jorgemd24 dc1fcb6
Rename file
jorgemd24 e77bdbf
Add tests
jorgemd24 61a4c5b
Update phpunit polyfills to 1.1 for WP 6.4
83e016a
Merge branch 'develop' into feature/google-api-project
jorgemd24 6076fc1
Merge branch 'feature/google-api-project' into add/gla_syncable_filter
jorgemd24 2f81f35
Fix eslint errors
jorgemd24 686b966
Fix phpcs tests
jorgemd24 26f8c7b
Rename post_types_to_filter
jorgemd24 2a5d4b7
Tweak formatting
jorgemd24 e78d7d0
Check for the value of gla_syncable
jorgemd24 5ec640e
Tweaks filter function names and PHPDocs
jorgemd24 b84999b
Use the ChannelVisibility constants
jorgemd24 faa9c56
Merge pull request #2152 from woocommerce/add/gla_syncable_filter
jorgemd24 ef3a011
Merge branch 'develop' into feature/google-api-project
jorgemd24 f673381
Create NotificationsService
puntope 897e2d1
Call Notify on Product changes
puntope 8587db5
Update tests
puntope 80c27f0
Start `release/2.5.13`.
github-actions[bot] ca4e35a
Update readme.txt
caa952a
Set migration version number
704efb7
Product version bump update
1781950
Changelog update
dd7f8de
Update hooks documentation from branch.
github-actions[bot] 7072aea
Add (budget and audiences) tracking for Onboarding completed with Ads
puntope 7da36c0
Add audiences and budget inside existing gla_onboarding_complete_with…
puntope 721c0b2
Prevent undefined country codes
puntope abf46d0
Change the onboarding to require a connected Google Ads account and m…
eason9487 c5f5436
Hide the content about the ad budget in the Boost card before a Googl…
eason9487 4e80346
Update tracking README.
eason9487 0453a6d
Update budget recommendation text
martynmjones 138b256
Fix the budget recommendation E2E tests for PR #2153 after cherry-pic…
eason9487 cc8fe7b
Add more utils to mock requests for E2E tests.
eason9487 2d976e3
Adjust E2E tests to reflect the change of requiring Google Ads connec…
eason9487 ee00514
Fix the problem that E2E util `checkFAQExpandable` doesn't wait for t…
eason9487 ebc1830
Change tested PHP versions
mikkamp 5722721
Generate coverage report when testing on PHP 8.2
mikkamp 789400d
Fix price in purchase event
jorgemd24 1be66fb
Start `release/2.5.14`.
github-actions[bot] a4f9e73
Update Readme.txt
puntope fd6fc0d
Product version bump update
puntope 2d50495
Changelog update
puntope 95bad26
Update hooks documentation from branch.
github-actions[bot] adf7b88
Update link for developer.woo.com
mikkamp 0577969
WIP
jorgemd24 39eb4e7
Merge branch 'feature/google-api-project' into add/api-pull-update-hooks
puntope ac29447
Apply review comments
puntope 96fddfb
Merge pull request #2190 from woocommerce/add/api-pull-update-hooks
puntope ce8b86f
Scheduled batched notifications using meta handler
puntope d8cebdb
Tweak logic for schedule notifications
puntope 832d0dc
Tests for Notification Service
puntope 94c4fb6
Tests for ProductHelper
puntope 0386c74
Update docs
puntope 51b729f
Update tests
puntope 619123f
Add tests for Notification
puntope d85d7ed
PHPCS
puntope a60ac81
Fix package path
puntope c47b7fa
Fix tests dependencies
puntope b716805
Fix tests dependencies
puntope d4c2d37
Remove trailing comma in constructor
puntope 545cd22
Refactor route param name
puntope 8ee54d1
Remove identation
puntope fd11304
Remove identation from functions
puntope 3d9b4bc
Remove unused dependency
puntope ba7ed8f
Add params in function signature
puntope b3b0735
Avoid item id to be null
puntope 8940067
Refactor dependencies
puntope a1eaad6
Refactor tests
puntope a1d5f22
PHPCS
puntope d3a641f
Change doc
puntope b9af9f1
Remove filter notification products
puntope 82795a7
Remove unused dependency
puntope 99f5b9e
Add useful hooks
puntope 08efcce
Add missing return types
puntope d93c7b7
Remove extra space
puntope cbb00a2
Add missing docs
puntope 677e4ec
Clarify docs
puntope 6315209
Verify if product is synced in MC
puntope de3e24c
Update docs
puntope 65dff81
Add Tests for ProductNotificationJob
puntope ac3f6cc
Remove PENDING_DELETE as a valid status for has_notified_cretion
puntope 75e4c96
Remove PENDING_DELETE as a valid status for has_notified_cretion
puntope 3056459
Remove unused dependency
puntope 2bb00ca
Add return type for void
puntope 3b1ef31
WIP: Add product view report
jorgemd24 bd3e0b6
Merge pull request #2202 from woocommerce/add/hooks-api-pull-metas
puntope 252e9ed
Fix PHPCS in GoogleListingsAndAdsPlugin
puntope 75a61ef
Solve PHPCS
puntope c4fde99
Remove old wrong code
puntope 7fd1766
Remove unsupported return type
puntope b4fa9c5
PHPCS for tests
puntope b2839a1
WIP - Get stats with Merchant report
jorgemd24 bbf3d3c
Refactor to get offer id for new and old products.
jorgemd24 a2fa2f5
Handle page size
jorgemd24 e79488c
Merge pull request #2228 from woocommerce/fix/phpcs
puntope 3fdccab
Fix issue with empty results
jorgemd24 7b5b178
Merge branch 'develop' into add/product-view-report-query
jorgemd24 50e108c
Fix typo
jorgemd24 44c7c4d
Merge branch 'develop' into feature/google-api-project
jorgemd24 fb619db
Merge branch 'feature/google-api-project' into add/product-view-repor…
jorgemd24 30aa787
Fix PHPDocs
jorgemd24 2185426
Remove extra comment
jorgemd24 9f78ac3
Change callback with inline calling
jorgemd24 d4df943
Change spread operator with array_merge
jorgemd24 41decb2
Fix typo expiration date
jorgemd24 82aadc1
Fix typo expiration date
jorgemd24 9592a80
Refactor get_product_view_query
jorgemd24 6c1b818
Add UpdateMerchantStatuses Job
jorgemd24 2657541
Remove unused plugin helper
jorgemd24 16b27b3
Remove get_offer_id function as we will fetch all products
jorgemd24 fdaaf30
Rename function convert_aggregated_status_to_mc_status
jorgemd24 2cfc1f2
Change query not synced products
jorgemd24 d8da89b
Skip product from status count if it is not sync ready
jorgemd24 8c6807c
Fix warning undefined index
jorgemd24 7a13ccc
Add ShoppingContentDateTrait
jorgemd24 39608de
Rename get_product_view_report method and increase limit size
jorgemd24 71ba5c5
Refactor calculate product statuses
jorgemd24 3138785
Rename Update merchant product status job
jorgemd24 6426ea6
Adjust UpdateMerchantProductStatuses name
jorgemd24 7d1ef5a
Schedule the job if mc_status is not set
jorgemd24 ea936e6
Adjust product statiscits controller
jorgemd24 a68d980
Tweak tests test_find_mc_not_synced_product_ids
jorgemd24 09ec214
Remove unused ViewReportQuery filter
jorgemd24 0e92124
Schdule job if force refresh
jorgemd24 9451680
Remove schedule job from the controller
jorgemd24 497586b
Remove extra space
jorgemd24 c0138fa
Remove unused dependency
jorgemd24 122d684
Remove extra string when logging message
jorgemd24 930469e
Fix typo DateTime
jorgemd24 0e90b7d
Move responsability of Merchant Report
jorgemd24 8b85a6a
Remove unused dependency
jorgemd24 1cf0178
Add filter product report batch size
jorgemd24 264cd27
Check if the job is scheduled
jorgemd24 679b143
Move ShoppingContentDateTrait
jorgemd24 2123e0b
Update PHPDocs and remove unnecessary $rows variable
jorgemd24 4c304f3
Show error message when unable to retrieve Product View Report
jorgemd24 56d20b5
Rename methods
jorgemd24 319a7a1
Remove ProductMetaHandler::KEY_VISIBILITY from not_synced_product_ids
jorgemd24 af810b1
Add comment so we can remove ProductMetaHandler::KEY_SYNC_STATUS
jorgemd24 7b0f3b2
Revert "Merge branch 'feature/google-api-project' into add/product-vi…
jorgemd24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare( strict_types=1 ); | ||
|
||
namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Query; | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Class MerchantProductViewReportQuery | ||
* | ||
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Query | ||
*/ | ||
class MerchantProductViewReportQuery extends MerchantQuery { | ||
|
||
use ReportQueryTrait; | ||
|
||
/** | ||
* Query constructor. | ||
* | ||
* @param array $args Query arguments. | ||
*/ | ||
public function __construct( array $args ) { | ||
parent::__construct( 'ProductView' ); | ||
$this->set_initial_columns(); | ||
$this->handle_query_args( $args ); | ||
} | ||
|
||
|
||
/** | ||
* Filter the query by a list of ID's. | ||
* | ||
* @param array $ids list of ID's to filter by. | ||
* | ||
* @return $this | ||
*/ | ||
public function filter( array $ids ): QueryInterface { | ||
// No filtering used for product view report. | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set the initial columns for this query. | ||
*/ | ||
protected function set_initial_columns() { | ||
$this->columns( | ||
[ | ||
'id' => 'product_view.id', | ||
'offer_id' => 'product_view.offer_id', | ||
'expiration_date' => 'product_view.expiration_date', | ||
'status' => 'product_view.aggregated_destination_status', | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare( strict_types=1 ); | ||
|
||
namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Google; | ||
|
||
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\Date as ShoppingContentDate; | ||
use DateTime; | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Trait ShoppingContentDateTrait | ||
* | ||
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Google | ||
*/ | ||
trait ShoppingContentDateTrait { | ||
|
||
/** | ||
* Convert ShoppingContentDate to DateTime. | ||
* | ||
* @param ShoppingContentDate $date The Google date. | ||
* | ||
* @return DateTime|false The date converted or false if the date is invalid. | ||
*/ | ||
protected function convert_shopping_content_date( ShoppingContentDate $date ) { | ||
return DateTime::createFromFormat( 'Y-m-d|', "{$date->getYear()}-{$date->getMonth()}-{$date->getDay()}" ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
declare( strict_types=1 ); | ||
|
||
namespace Automattic\WooCommerce\GoogleListingsAndAds\Jobs; | ||
|
||
use Automattic\WooCommerce\GoogleListingsAndAds\ActionScheduler\ActionSchedulerInterface; | ||
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService; | ||
use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\MerchantReport; | ||
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantStatuses; | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Class UpdateMerchantProductStatuses | ||
* | ||
* Update Product Stats | ||
* | ||
* Note: The job will not start if it is already running or if the Google Merchant Center account is not connected. | ||
* | ||
* @package Automattic\WooCommerce\GoogleListingsAndAds\Jobs | ||
* | ||
* @since x.x.x | ||
*/ | ||
class UpdateMerchantProductStatuses extends AbstractActionSchedulerJob { | ||
/** | ||
* @var MerchantCenterService | ||
*/ | ||
protected $merchant_center; | ||
|
||
/** | ||
* @var MerchantReport | ||
*/ | ||
protected $merchant_report; | ||
|
||
/** | ||
* @var MerchantStatuses | ||
*/ | ||
|
||
protected $merchant_statuses; | ||
|
||
/** | ||
* UpdateShippingSettings constructor. | ||
* | ||
* @param ActionSchedulerInterface $action_scheduler | ||
* @param ActionSchedulerJobMonitor $monitor | ||
* @param MerchantCenterService $merchant_center | ||
* @param MerchantReport $merchant_report | ||
* @param MerchantStatuses $merchant_statuses | ||
*/ | ||
public function __construct( ActionSchedulerInterface $action_scheduler, ActionSchedulerJobMonitor $monitor, MerchantCenterService $merchant_center, MerchantReport $merchant_report, MerchantStatuses $merchant_statuses ) { | ||
parent::__construct( $action_scheduler, $monitor ); | ||
$this->merchant_center = $merchant_center; | ||
$this->merchant_report = $merchant_report; | ||
$this->merchant_statuses = $merchant_statuses; | ||
} | ||
|
||
/** | ||
* Get the name of the job. | ||
* | ||
* @return string | ||
*/ | ||
public function get_name(): string { | ||
return 'update_merchant_product_statuses'; | ||
} | ||
|
||
/** | ||
* Can the job be scheduled. | ||
* | ||
* @param array|null $args | ||
* | ||
* @return bool Returns true if the job can be scheduled. | ||
*/ | ||
public function can_schedule( $args = [] ): bool { | ||
return parent::can_schedule( $args ) && $this->merchant_center->is_connected(); | ||
} | ||
|
||
/** | ||
* Process the job. | ||
* | ||
* @param int[] $items An array of job arguments. | ||
* | ||
* @throws JobException If the shipping settings cannot be synced. | ||
*/ | ||
public function process_items( array $items ) { | ||
$next_page_token = null; | ||
|
||
do { | ||
$results = $this->merchant_report->get_product_view_report( $next_page_token ); | ||
|
||
$this->merchant_statuses->process_product_statuses( $results['statuses'] ); | ||
|
||
$next_page_token = $results['next_page']; | ||
|
||
} while ( $next_page_token ); | ||
|
||
$this->merchant_statuses->update_product_stats(); | ||
} | ||
|
||
/** | ||
* Schedule the job. | ||
* | ||
* @param array $args - arguments. | ||
*/ | ||
public function schedule( array $args = [] ) { | ||
if ( $this->can_schedule() ) { | ||
$this->action_scheduler->schedule_immediate( $this->get_process_item_hook() ); | ||
} | ||
} | ||
|
||
/** | ||
* The job is considered to be scheduled if the "process_item" action is currently pending or in-progress. | ||
* | ||
* @return bool | ||
*/ | ||
public function is_scheduled(): bool { | ||
return $this->is_running(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not a big deal, but technically we've only tried extracting the product ID from the string, we haven't actually checked if it exists.
This makes me wonder though, we are extracting from
$product_view->getId()
, why is both theoffer_id
andid
included in the query MerchantProductViewReportQuery then? Not a big deal to leave it there, but was just curious. Seems likegetOfferId()
would return a much shorter string.