Refactor data source poller classes for marketing recommendations, payment gateway suggestions, shipping partner suggestions, inbox notifications, remote free extensions, and WooPayments promotion
- Refactor the data source poller classes for marketing recommendations, payment gateway suggestions, shipping partner suggestions, inbox notifications, remote free extensions, and WooPayments promotion to use a dynamic base URL for the data sources. - Update the deprecated DATA_SOURCES constant to an empty array in each class. - Add a new method get_data_sources() in each class to return the updated data sources with the dynamic base URL. - Modify the constructor of each class to use the get_data_sources() method instead of the deprecated DATA_SOURCES constant.
This commit is contained in:
parent
b5c43db303
commit
29408da9d2
|
@ -3,6 +3,7 @@
|
|||
namespace Automattic\WooCommerce\Admin\Features\MarketingRecommendations;
|
||||
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
|
||||
use WC_Helper;
|
||||
|
||||
/**
|
||||
* Specs data source poller class for marketing recommendations.
|
||||
|
@ -16,15 +17,15 @@ class MarketingRecommendationsDataSourcePoller extends DataSourcePoller {
|
|||
|
||||
/**
|
||||
* Default data sources array.
|
||||
*
|
||||
* @deprecated since 9.5.0. Use get_data_sources() instead.
|
||||
*/
|
||||
const DATA_SOURCES = array(
|
||||
'https://woocommerce.com/wp-json/wccom/marketing-tab/1.3/recommendations.json',
|
||||
);
|
||||
const DATA_SOURCES = array();
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
*
|
||||
* @var Analytics instance
|
||||
* @var MarketingRecommendationsDataSourcePoller instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
|
@ -35,7 +36,7 @@ class MarketingRecommendationsDataSourcePoller extends DataSourcePoller {
|
|||
if ( ! self::$instance ) {
|
||||
self::$instance = new self(
|
||||
self::ID,
|
||||
self::DATA_SOURCES,
|
||||
self::get_data_sources(),
|
||||
array(
|
||||
'spec_key' => 'product',
|
||||
)
|
||||
|
@ -43,4 +44,15 @@ class MarketingRecommendationsDataSourcePoller extends DataSourcePoller {
|
|||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data sources.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_data_sources() {
|
||||
return array(
|
||||
WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/marketing-tab/1.3/recommendations.json',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions;
|
||||
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
|
||||
use WC_Helper;
|
||||
|
||||
/**
|
||||
* Specs data source poller class for payment gateway suggestions.
|
||||
|
@ -16,15 +17,15 @@ class PaymentGatewaySuggestionsDataSourcePoller extends DataSourcePoller {
|
|||
|
||||
/**
|
||||
* Default data sources array.
|
||||
*
|
||||
* @deprecated since 9.5.0. Use get_data_sources() instead.
|
||||
*/
|
||||
const DATA_SOURCES = array(
|
||||
'https://woocommerce.com/wp-json/wccom/payment-gateway-suggestions/2.0/suggestions.json',
|
||||
);
|
||||
const DATA_SOURCES = array();
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
*
|
||||
* @var Analytics instance
|
||||
* @var PaymentGatewaySuggestionsDataSourcePoller instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
|
@ -33,21 +34,33 @@ class PaymentGatewaySuggestionsDataSourcePoller extends DataSourcePoller {
|
|||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! self::$instance ) {
|
||||
// Add country query param to data sources.
|
||||
$base_location = wc_get_base_location();
|
||||
$data_sources = array_map(
|
||||
function( $url ) use ( $base_location ) {
|
||||
return add_query_arg(
|
||||
'country',
|
||||
$base_location['country'],
|
||||
$url
|
||||
);
|
||||
},
|
||||
self::DATA_SOURCES
|
||||
);
|
||||
|
||||
self::$instance = new self( self::ID, $data_sources );
|
||||
self::$instance = new self( self::ID, self::get_data_sources() );
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data sources with dynamic base URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_data_sources() {
|
||||
$data_sources = array(
|
||||
WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/payment-gateway-suggestions/2.0/suggestions.json',
|
||||
);
|
||||
|
||||
// Add country query param to data sources.
|
||||
$base_location = wc_get_base_location();
|
||||
$data_sources_with_country = array_map(
|
||||
function ( $url ) use ( $base_location ) {
|
||||
return add_query_arg(
|
||||
'country',
|
||||
$base_location['country'],
|
||||
$url
|
||||
);
|
||||
},
|
||||
$data_sources
|
||||
);
|
||||
return $data_sources_with_country;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Automattic\WooCommerce\Admin\Features\ShippingPartnerSuggestions;
|
||||
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
|
||||
use WC_Helper;
|
||||
|
||||
/**
|
||||
* Specs data source poller class for shipping partner suggestions.
|
||||
|
@ -16,10 +17,10 @@ class ShippingPartnerSuggestionsDataSourcePoller extends DataSourcePoller {
|
|||
|
||||
/**
|
||||
* Default data sources array.
|
||||
*
|
||||
* @deprecated since 9.5.0. Use get_data_sources() instead.
|
||||
*/
|
||||
const DATA_SOURCES = array(
|
||||
'https://woocommerce.com/wp-json/wccom/shipping-partner-suggestions/2.0/suggestions.json',
|
||||
);
|
||||
const DATA_SOURCES = array();
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
|
@ -33,8 +34,19 @@ class ShippingPartnerSuggestionsDataSourcePoller extends DataSourcePoller {
|
|||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! self::$instance ) {
|
||||
self::$instance = new self( self::ID, self::DATA_SOURCES );
|
||||
self::$instance = new self( self::ID, self::get_data_sources() );
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data sources.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_data_sources() {
|
||||
return array(
|
||||
WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/shipping-partner-suggestions/2.0/suggestions.json',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ defined( 'ABSPATH' ) || exit;
|
|||
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\GetRuleProcessor;
|
||||
use WC_Helper;
|
||||
|
||||
/**
|
||||
* Specs data source poller class.
|
||||
|
@ -16,14 +17,19 @@ use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\GetRuleProcessor;
|
|||
* stores the specs in to the database as an option.
|
||||
*/
|
||||
class RemoteInboxNotificationsDataSourcePoller extends DataSourcePoller {
|
||||
const ID = 'remote_inbox_notifications';
|
||||
const DATA_SOURCES = array(
|
||||
'https://woocommerce.com/wp-json/wccom/inbox-notifications/2.0/notifications.json',
|
||||
);
|
||||
const ID = 'remote_inbox_notifications';
|
||||
|
||||
/**
|
||||
* Default data sources array.
|
||||
*
|
||||
* @deprecated since 9.5.0. Use get_data_sources() instead.
|
||||
*/
|
||||
const DATA_SOURCES = array();
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
*
|
||||
* @var Analytics instance
|
||||
* @var RemoteInboxNotificationsDataSourcePoller instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
|
@ -34,7 +40,7 @@ class RemoteInboxNotificationsDataSourcePoller extends DataSourcePoller {
|
|||
if ( ! self::$instance ) {
|
||||
self::$instance = new self(
|
||||
self::ID,
|
||||
self::DATA_SOURCES,
|
||||
self::get_data_sources(),
|
||||
array(
|
||||
'spec_key' => 'slug',
|
||||
)
|
||||
|
@ -218,4 +224,15 @@ class RemoteInboxNotificationsDataSourcePoller extends DataSourcePoller {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data sources.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_data_sources() {
|
||||
return array(
|
||||
WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/inbox-notifications/2.0/notifications.json',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
|
||||
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
|
||||
use WC_Helper;
|
||||
/**
|
||||
* Specs data source poller class for remote free extensions.
|
||||
*/
|
||||
|
@ -10,14 +11,17 @@ class RemoteFreeExtensionsDataSourcePoller extends DataSourcePoller {
|
|||
|
||||
const ID = 'remote_free_extensions';
|
||||
|
||||
const DATA_SOURCES = array(
|
||||
'https://woocommerce.com/wp-json/wccom/obw-free-extensions/4.0/extensions.json',
|
||||
);
|
||||
/**
|
||||
* Default data sources array.
|
||||
*
|
||||
* @deprecated since 9.5.0. Use get_data_sources() instead.
|
||||
*/
|
||||
const DATA_SOURCES = array();
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
*
|
||||
* @var Analytics instance
|
||||
* @var RemoteFreeExtensionsDataSourcePoller instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
|
@ -28,7 +32,7 @@ class RemoteFreeExtensionsDataSourcePoller extends DataSourcePoller {
|
|||
if ( ! self::$instance ) {
|
||||
self::$instance = new self(
|
||||
self::ID,
|
||||
self::DATA_SOURCES,
|
||||
self::get_data_sources(),
|
||||
array(
|
||||
'spec_key' => 'key',
|
||||
)
|
||||
|
@ -36,4 +40,15 @@ class RemoteFreeExtensionsDataSourcePoller extends DataSourcePoller {
|
|||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data sources.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_data_sources() {
|
||||
return array(
|
||||
WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/obw-free-extensions/4.0/extensions.json',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Automattic\WooCommerce\Internal\Admin\WCPayPromotion;
|
||||
|
||||
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
|
||||
use WC_Helper;
|
||||
|
||||
/**
|
||||
* Specs data source poller class for WooPayments Promotion.
|
||||
|
@ -13,10 +14,10 @@ class WCPayPromotionDataSourcePoller extends DataSourcePoller {
|
|||
|
||||
/**
|
||||
* Default data sources array.
|
||||
*
|
||||
* @deprecated since 9.5.0. Use get_data_sources() instead.
|
||||
*/
|
||||
const DATA_SOURCES = array(
|
||||
'https://woocommerce.com/wp-json/wccom/payment-gateway-suggestions/2.0/payment-method/promotions.json',
|
||||
);
|
||||
const DATA_SOURCES = array();
|
||||
|
||||
/**
|
||||
* Class instance.
|
||||
|
@ -30,21 +31,33 @@ class WCPayPromotionDataSourcePoller extends DataSourcePoller {
|
|||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! self::$instance ) {
|
||||
// Add country query param to data sources.
|
||||
$base_location = wc_get_base_location();
|
||||
$data_sources = array_map(
|
||||
function ( $url ) use ( $base_location ) {
|
||||
return add_query_arg(
|
||||
'country',
|
||||
$base_location['country'] ?? '',
|
||||
$url
|
||||
);
|
||||
},
|
||||
self::DATA_SOURCES
|
||||
);
|
||||
|
||||
self::$instance = new self( self::ID, $data_sources );
|
||||
self::$instance = new self( self::ID, self::get_data_sources() );
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data sources.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_data_sources() {
|
||||
$data_sources = array(
|
||||
WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/payment-gateway-suggestions/2.0/payment-method/promotions.json',
|
||||
);
|
||||
|
||||
// Add country query param to data sources.
|
||||
$base_location = wc_get_base_location();
|
||||
$data_sources_with_country = array_map(
|
||||
function ( $url ) use ( $base_location ) {
|
||||
return add_query_arg(
|
||||
'country',
|
||||
$base_location['country'],
|
||||
$url
|
||||
);
|
||||
},
|
||||
$data_sources
|
||||
);
|
||||
return $data_sources_with_country;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue