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/switch feed v5 #849

Merged
merged 85 commits into from
Dec 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
f35b6cf
Add automerge-released-trunk workflow
tomalec Jul 24, 2023
6f6508b
Add silent exception handling.
message-dimke Jul 25, 2023
0ce46d6
Fix PHP code styling error.
message-dimke Jul 25, 2023
b2c389c
Adds logic to dynamically display spend requirement and credits given…
Aug 15, 2023
46fb8eb
Code cleanup.
Aug 15, 2023
121cb7a
Fixes PHPCS and JS linting issues.
Aug 15, 2023
5b55682
Adds translator comment and values with sprintf.
Aug 17, 2023
864a4d0
Fixes JS linting errors. Passed spendRequire and creditsGiven values …
Aug 17, 2023
3e9c12b
Dyanamically generates amount required to be spent and the credits gi…
Aug 18, 2023
211591d
Revert "Dyanamically generates amount required to be spent and the cr…
Aug 18, 2023
fce98ae
Merge branch 'develop' into fix/ads-credit-notice-currency
Aug 18, 2023
ef1e96c
Dynamic generation of credits given and spend requirement amount on A…
Aug 18, 2023
d4f1383
Dynamic generation of credits given and spend requirement amount on T…
Aug 21, 2023
ecbccd7
Fixes JS linting issue.
Aug 21, 2023
4c40c3c
Fixes JS linting issue.
Aug 21, 2023
5c47fa8
Adds logic to dynamically display credits info in FAQ section on Land…
Aug 21, 2023
799b123
Updates phpunit version, unit tests and matrix for PHP8.2 compatibility.
Aug 24, 2023
9e3eec9
Reduces PHP unit tests checks in git workflow.
Aug 24, 2023
52f816e
Eliminates Automatic conversion of false to array is deprecated warning.
Aug 24, 2023
b25bfcf
Updates minimum PHP to 7.4 and PHP 8.2 for coding standards workflow.
Aug 25, 2023
a0f76f9
Remove Unit test git workflow check for PHP7.3.
Aug 25, 2023
606d57c
Fixes PHPCS issues.
Aug 25, 2023
dd33d7a
Fix uninstall procedure.
budzanowski Aug 31, 2023
4dfac99
Fix PHPCS issues.
budzanowski Sep 1, 2023
f49ed33
Merge pull request #817 from woocommerce/fix/uninstall-procedure
budzanowski Sep 3, 2023
7c61566
Dynamically generate amount required to spend for credits to be given…
krutidugade Sep 5, 2023
08dc976
Product version bump update
rawdreeg Sep 5, 2023
9c64bda
Changelog update
rawdreeg Sep 5, 2023
0cd2350
Merge pull request #818 from woocommerce/release/1.3.9
rawdreeg Sep 5, 2023
80ca36c
Merge pull request #819 from woocommerce/release/1.3.9
rawdreeg Sep 5, 2023
facd858
Merge pull request #815 from woocommerce/dev/update-php-unit-tests
message-dimke Sep 11, 2023
d03702c
Start `release/1.3.10`.
github-actions[bot] Sep 12, 2023
fd6a4b3
Product version bump update
ecgan Sep 12, 2023
8a13a77
Changelog update
ecgan Sep 12, 2023
06abab7
Merge pull request #820 from woocommerce/release/1.3.10
ecgan Sep 12, 2023
65ac8b3
Merge pull request #821 from woocommerce/trunk
ecgan Sep 12, 2023
261461f
Merge pull request #791 from woocommerce/dev/automerge
tomalec Sep 19, 2023
266025c
Add phpcs changed conde style check on changed files only.
message-dimke Oct 1, 2023
70473dc
Decrease the number of php versions to check against.
message-dimke Oct 1, 2023
9797c0a
Make GitHub Action skip linter warnings. Update WooCommerce sniffs de…
message-dimke Oct 9, 2023
2549c69
Product version bump update
ibndawood Oct 10, 2023
8dd5e5b
Changelog update
ibndawood Oct 10, 2023
4d759b0
Release v1.3.11 (#829)
ibndawood Oct 10, 2023
12cc9fc
Merge pull request #830 from woocommerce/trunk
ibndawood Oct 10, 2023
bac6487
Merge pull request #822 from woocommerce/add/phpcs-changed
message-dimke Oct 16, 2023
f0d319f
Product version bump update
message-dimke Oct 19, 2023
10d74d0
Changelog update
message-dimke Oct 19, 2023
0717c38
Merge pull request #835 from woocommerce/release/1.3.12
message-dimke Oct 23, 2023
c5aa508
Merge pull request #836 from woocommerce/trunk
message-dimke Oct 23, 2023
6e7f1fb
Update README.md
message-dimke Nov 2, 2023
9ac7646
Update woocommerce.com → woo.com in documentation
layoutd Nov 2, 2023
e8cc400
Update woocommerce.com → woo.com in composer.json
layoutd Nov 2, 2023
b880441
Update woocommerce.com → woo.com in plugin header
layoutd Nov 2, 2023
d8c193c
Update woocommerce.com → woo.com in Recommendations API URL
layoutd Nov 2, 2023
9894af6
Update woocommerce.com → woo.com in marketing tab icon URL
layoutd Nov 2, 2023
9050e21
Update woocommerce.com → woo.com in readme.txt
layoutd Nov 2, 2023
8cb93f5
Remove Spanish geo from feature requests link
layoutd Nov 3, 2023
50e26f3
Merge pull request #837 from woocommerce/update/new-woo-domain
layoutd Nov 7, 2023
dbdb9fb
Start `release/1.3.13`.
github-actions[bot] Nov 7, 2023
a48dd61
Product version bump update
ecgan Nov 7, 2023
f2b97f3
Changelog update
ecgan Nov 7, 2023
7179936
Merge pull request #842 from woocommerce/release/1.3.13
ecgan Nov 7, 2023
8b08e59
Merge pull request #843 from woocommerce/trunk
ecgan Nov 7, 2023
b1013e2
Merge pull request #792 from woocommerce/add/users-me-businesse-excep…
message-dimke Nov 10, 2023
b628810
Check feed_location to contain absolute url.
message-dimke Nov 10, 2023
fb6e091
Porting feed status change endpoints and invalidate cache method.
message-dimke Nov 10, 2023
c49ecae
Fixing phpcs errors. Adding feed status constants.
message-dimke Nov 13, 2023
c9e38a0
Minor exception naming adjustments.
message-dimke Nov 13, 2023
790b65f
Merge remote-tracking branch 'origin/pinterest-v5-integration-branch'…
message-dimke Nov 13, 2023
273fd2e
Fix update feed endpoints how parameters are passed to Pinterest. Add…
message-dimke Nov 13, 2023
5da7c81
Renaming some API methods. Implementing feed create method. Getting r…
message-dimke Nov 14, 2023
764e7bb
Integrating use of renamed APIs.
message-dimke Nov 14, 2023
1365367
Fixing bugs with wrong API endpoint URLs. Adjusting method comments. …
message-dimke Nov 27, 2023
06dd8df
Adding feed location check to make sure this is a feed originated fro…
message-dimke Nov 29, 2023
50186d8
Fixing phpcs errors when running PR checks.
message-dimke Nov 29, 2023
8f88773
Fixing phpcs errors when running PR checks.
message-dimke Nov 29, 2023
22c6b36
Fixing phpcs errors when running PR checks.
message-dimke Nov 29, 2023
52cf5b6
Adding php unit test github workflow file, same as we have on dev wit…
message-dimke Nov 29, 2023
cf89734
Merge branch 'develop' into add/switch-feed-v5
message-dimke Nov 29, 2023
b3bd566
Catching up with develop branch and updating the lock file.
message-dimke Nov 29, 2023
a20e33a
Fixing PHPCS errors after merging with develop.
message-dimke Nov 29, 2023
68d445a
Fixing PHPCS errors.
message-dimke Nov 29, 2023
52996e6
Fix unit tests inheritance error.
message-dimke Nov 29, 2023
ff987fd
Fix php cs errors
message-dimke Nov 29, 2023
b3d4919
Update phpcs rules to exclude a check for a specific @since version a…
message-dimke Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing bugs with wrong API endpoint URLs. Adjusting method comments. …
…Adjusting create feed endpoint to provide a unique feed name. Reverting back some Base API method names.
message-dimke committed Nov 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1365367271c2883cf3137f0a78b499d14708e8c6
35 changes: 19 additions & 16 deletions src/API/APIV5.php
Original file line number Diff line number Diff line change
@@ -79,17 +79,18 @@ public static function get_account_info() {
* @since x.x.x
*
* @return array {
* Ad Accounts countries
* Ad Accounts countries
*
* @type array[] $items {
* @type string $code Country ID from ISO 3166-1 alpha-2.
* @type string $currency Country currency.
* @type int $index Country index
* @type string $name Country name.
* }
* @type array[] $items {
* @type string $code Country ID from ISO 3166-1 alpha-2.
* @type string $currency Country currency.
* @type int $index Country index
* @type string $name Country name.
* }
* }
* @throws PinterestApiException
*/
public static function get_list_of_ads_supported_countries() {
public static function get_list_of_ads_supported_countries(): array {
$request_url = 'resources/ad_account_countries';
return self::make_request( $request_url, 'GET', array(), '', 2 * DAY_IN_SECONDS );
}
@@ -334,7 +335,7 @@ public static function domain_metatag_verification_request( string $domain ): ar
*
* @link https://developers.pinterest.com/docs/api/v5/#operation/feeds/create
*
* @param array $data {
* @param array $data {
* Feed data.
*
* @type string $name A human-friendly name associated to a given feed. This value is currently nullable due to historical reasons. It is expected to become non-nullable in the future.
@@ -362,9 +363,9 @@ public static function domain_metatag_verification_request( string $domain ): ar
*
* @return array
*
* @throws PinterestApiException
* @throws PinterestApiException If the request fails with other than 2xx status.
*/
public static function create_feed( $data, $ad_account_id ): array {
public static function create_feed( array $data, string $ad_account_id ): array {
return self::make_request(
"catalogs/feeds?ad_account_id={$ad_account_id}",
'POST',
@@ -412,7 +413,7 @@ public static function create_feed( $data, $ad_account_id ): array {
* }
* @throws PinterestApiException If the request fails with 500 status.
*/
public static function get_feeds($ad_account_id ) {
public static function get_feeds( string $ad_account_id ): array {
return self::make_request(
"catalogs/feeds?ad_account_id={$ad_account_id}",
'GET',
@@ -449,8 +450,9 @@ public static function invalidate_feeds_cache( string $ad_account_id ): bool {
* @param string $feed_id The ID of the feed to be enabled.
*
* @return mixed
* @throws PinterestApiException If API request ends up other than 2xx status.
*/
public static function enable_feed($ad_account_id, $feed_id ) {
public static function enable_feed( string $ad_account_id, string $feed_id ): array {
return static::update_feed_status( $feed_id, Feeds::FEED_STATUS_ACTIVE, $ad_account_id );
}

@@ -463,8 +465,9 @@ public static function enable_feed($ad_account_id, $feed_id ) {
* @param string $feed_id The ID of the feed to be disabled.
*
* @return mixed
* @throws PinterestApiException If API request ends up other than 2xx status.
*/
public static function disable_feed($ad_account_id, $feed_id ) {
public static function disable_feed( string $ad_account_id, string $feed_id ): array {
return static::update_feed_status( $feed_id, Feeds::FEED_STATUS_INACTIVE, $ad_account_id );
}

@@ -480,9 +483,9 @@ public static function disable_feed($ad_account_id, $feed_id ) {
* @return array
* @throws PinterestApiException If API request ends up other than 2xx status.
*/
private static function update_feed_status( $feed_id, $status, $ad_account_id ) {
private static function update_feed_status( string $feed_id, string $status, string $ad_account_id ): array {
return self::make_request(
"catalog/feeds/{$feed_id}?ad_account_id={$ad_account_id}",
"catalogs/feeds/{$feed_id}?ad_account_id={$ad_account_id}",
'PATCH',
array(
'status' => $status,
13 changes: 8 additions & 5 deletions src/API/Base.php
Original file line number Diff line number Diff line change
@@ -655,12 +655,13 @@ public static function update_merchant_feed( $merchant_id, $feed_id, $args ) {
*
* @since 1.2.13
*
* @param string $merchant_id The merchant ID the feed belongs to.
* @param string $merchant_id The merchant ID the feed belongs to.
* @param string $feed_profile_id The ID of the feed to be disabled.
*
* @return mixed
* @throws PinterestApiException
*/
public static function disable_feed($merchant_id, $feed_profile_id ) {
public static function disable_merchant_feed( $merchant_id, $feed_profile_id ): array {
return self::make_request(
"catalogs/disable_feed_profile/{$merchant_id}/{$feed_profile_id}/"
);
@@ -671,12 +672,13 @@ public static function disable_feed($merchant_id, $feed_profile_id ) {
*
* @since 1.2.13
*
* @param string $merchant_id The merchant ID the feed belongs to.
* @param string $merchant_id The merchant ID the feed belongs to.
* @param string $feed_profile_id The ID of the feed to be enabled.
*
* @return mixed
* @throws PinterestApiException
*/
public static function enable_feed($merchant_id, $feed_profile_id ) {
public static function enable_merchant_feed( $merchant_id, $feed_profile_id ): array {
return self::make_request(
"catalogs/enable_feed_profile/{$merchant_id}/{$feed_profile_id}/"
);
@@ -735,9 +737,10 @@ public static function invalidate_merchant_feeds_cache( $merchant_id, $include_d
* Get a specific merchant's feed report using the given arguments.
*
* @param string $merchant_id The merchant ID the feed belongs to.
* @param string $feed_id The ID of the feed.
* @param string $feed_id The ID of the feed.
*
* @return mixed
* @throws PinterestApiException
*/
public static function get_merchant_feed_report( $merchant_id, $feed_id ) {
return self::make_request(
46 changes: 12 additions & 34 deletions src/FeedRegistration.php
Original file line number Diff line number Diff line change
@@ -73,17 +73,17 @@ public function init() {
* Should be run on demand when settings change,
* and on a scheduled basis.
*
* @return mixed
* @return bool
*
* @throws Exception PHP Exception.
*/
public function handle_feed_registration() {
public function handle_feed_registration(): bool {

// Clean merchants error code.
$this->clear_merchant_error_code();

if ( ! self::feed_file_exists() ) {
self::log( 'Feed didn\'t fully generate yet. Retrying later.', 'debug' );
self::log( 'Feed did not fully generate yet. Retrying later.' );
// Feed is not generated yet, lets wait a bit longer.
return true;
}
@@ -101,7 +101,7 @@ public function handle_feed_registration() {
// translators: %s: Error message.
$error_message = "Could not register feed. Error: {$e->getMessage()}";
self::log( $error_message, 'error' );

return false;
} catch ( Throwable $th ) {
if ( method_exists( $th, 'get_pinterest_code' ) && 4163 === $th->get_pinterest_code() ) {
Pinterest_For_Woocommerce()::save_data( 'merchant_connected_diff_platform', true );
@@ -127,14 +127,14 @@ private function clear_merchant_error_code() {
/**
* Handles feed registration using the given arguments.
* Will try to create a merchant if none exists.
* Also if a different feed is registered, it will update using the URL in the
* Also, if a different feed is registered, it will update using the URL in the
* $feed_args.
*
* @return boolean
*
* @throws Exception PHP Exception.
*/
private static function register_feed() {
private static function register_feed(): bool {
$feed_id = Feeds::match_local_feed_configuration_to_registered_feeds();

// If no matching registered feed found try to create it.
@@ -162,6 +162,7 @@ private static function register_feed() {
* @param string $feed_id Feed ID.
*
* @return void
* @throws Exception PHP Exception.
*/
private static function feed_enable_status_maintenance( $feed_id ) {
// Check if the feed is enabled. If not, enable it.
@@ -182,6 +183,7 @@ private static function feed_enable_status_maintenance( $feed_id ) {
* @param string $feed_id Feed ID.
*
* @return void
* @throws Exception PHP Exception.
*/
public static function maybe_disable_stale_feeds_for_merchant( $feed_id ) {
$feeds = Feeds::get_feeds();
@@ -190,11 +192,6 @@ public static function maybe_disable_stale_feeds_for_merchant( $feed_id ) {
return;
}

$configs = LocalFeedConfigs::get_instance()->get_configurations();
$config = reset( $configs );
// Make sure this $local_path has a domain name.
$local_path = $config['feed_url'];

$invalidate_cache = false;

foreach ( $feeds as $feed ) {
@@ -203,27 +200,8 @@ public static function maybe_disable_stale_feeds_for_merchant( $feed_id ) {
continue;
}

// Only disable feeds that are registered as WooCommerce integration.
/*
if ( 'WOOCOMMERCE' !== $feed->integration_platform_type ) {
continue;
}
*/

/**
* Disable feeds only if their file URL matches, using the directory path for accurate identification. This
* method prevents the disabling of non-WooCommerce feeds that share the same merchant registration.
* Simultaneously, disable feeds registered for WooCommerce from the same host with different file names,
* ending with a suffix generated by the wp_generate_password function, as outlined in the LocalFeedConfigs
* class. Utilizing dirname eliminates the file name and suffix, leaving only the directory path for
* comparison.
*/
if ( dirname( $feed['location'] ) !== $local_path ) {
continue;
}

// Disable the feed if it is active.
if ( 'ACTIVE' === $feed['status'] ) {
if ( Feeds::FEED_STATUS_ACTIVE === $feed['status'] ) {
Feeds::disable_feed( $feed['id'] );
$invalidate_cache = true;
}
@@ -236,12 +214,12 @@ public static function maybe_disable_stale_feeds_for_merchant( $feed_id ) {

/**
* Checks if the feed file for the configured (In $state var) feed exists.
* This could be true as the feed is being generated, if its not the 1st time
* its been generated.
* This could be true as the feed is being generated, if it's not the 1st time
* it's been generated.
*
* @return bool
*/
public function feed_file_exists() {
public function feed_file_exists(): bool {
return $this->feed_file_operations->check_if_feed_file_exists();
}

21 changes: 14 additions & 7 deletions src/Feeds.php
Original file line number Diff line number Diff line change
@@ -40,25 +40,32 @@ public static function create_feed(): string {
$configs = LocalFeedConfigs::get_instance()->get_configurations();
$config = reset( $configs );


$default_country = Pinterest_For_Woocommerce()::get_base_country() ?? 'US';
$default_currency = get_woocommerce_currency();

/**
* Filters the default merchant name: pinterest_for_woocommerce_default_merchant_name.
* This vale appears in the feed configuration page in Pinterest.
* Filters the default feed name: pinterest_for_woocommerce_unique_feed_name.
* This vale appears in the Catalogues - Data sources page at Pinterest.
*
* @param string $feed_name The default feed name.
*/
$feed_name = apply_filters(
'pinterest_for_woocommerce_default_merchant_name',
esc_html__( 'Auto-created by Pinterest for WooCommerce', 'pinterest-for-woocommerce' )
'pinterest_for_woocommerce_unique_feed_name',
esc_html__(
"Created by Pinterest for WooCommerce {$default_country}-{$default_currency}.",
'pinterest-for-woocommerce'
)
);

$data = array(
'name' => $feed_name,
'format' => 'XML',
'location' => $config['feed_url'],
'catalog_type' => 'RETAIL',
'default_currency' => get_woocommerce_currency(),
'default_currency' => $default_currency,
'default_locale' => LocaleMapper::get_locale_for_api(),
'default_country' => Pinterest_For_Woocommerce()::get_base_country() ?? 'US',
'default_country' => $default_country,
'default_availability' => 'IN_STOCK',
);

@@ -141,7 +148,7 @@ public static function get_feeds(): array {
return $feeds['items'] ?? [];
} catch ( PinterestApiException $e ) {
Logger::log( $e->getMessage(), 'error' );
throw $e;
return [];
}
}