plugin updates
This commit is contained in:
@@ -93,6 +93,7 @@ class Init {
|
||||
'Automattic\WooCommerce\Admin\API\OnboardingTasks',
|
||||
'Automattic\WooCommerce\Admin\API\OnboardingThemes',
|
||||
'Automattic\WooCommerce\Admin\API\OnboardingPlugins',
|
||||
'Automattic\WooCommerce\Admin\API\OnboardingProducts',
|
||||
'Automattic\WooCommerce\Admin\API\NavigationFavorites',
|
||||
'Automattic\WooCommerce\Admin\API\Taxes',
|
||||
'Automattic\WooCommerce\Admin\API\MobileAppMagicLink',
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Automattic\WooCommerce\Admin\API;
|
||||
|
||||
use Automattic\WooCommerce\Admin\PluginsHelper;
|
||||
use Automattic\WooCommerce\Internal\Admin\Marketing\MarketingSpecs;
|
||||
use Automattic\WooCommerce\Admin\Features\MarketingRecommendations\Init as MarketingRecommendationsInit;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
@@ -103,16 +104,9 @@ class Marketing extends \WC_REST_Data_Controller {
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_recommended_plugins( $request ) {
|
||||
/**
|
||||
* MarketingSpecs class.
|
||||
*
|
||||
* @var MarketingSpecs $marketing_specs
|
||||
*/
|
||||
$marketing_specs = wc_get_container()->get( MarketingSpecs::class );
|
||||
|
||||
// Default to marketing category (if no category set).
|
||||
$category = ( ! empty( $request->get_param( 'category' ) ) ) ? $request->get_param( 'category' ) : 'marketing';
|
||||
$all_plugins = $marketing_specs->get_recommended_plugins();
|
||||
$all_plugins = MarketingRecommendationsInit::get_recommended_plugins();
|
||||
$valid_plugins = [];
|
||||
$per_page = $request->get_param( 'per_page' );
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class MarketingCampaigns extends WC_REST_Controller {
|
||||
$marketing_channels_service = wc_get_container()->get( MarketingChannelsService::class );
|
||||
|
||||
// Aggregate the campaigns from all registered marketing channels.
|
||||
$responses = [];
|
||||
$responses = array();
|
||||
foreach ( $marketing_channels_service->get_registered_channels() as $channel ) {
|
||||
foreach ( $channel->get_campaigns() as $campaign ) {
|
||||
$response = $this->prepare_item_for_response( $campaign, $request );
|
||||
@@ -141,18 +141,25 @@ class MarketingCampaigns extends WC_REST_Controller {
|
||||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
$data = [
|
||||
$data = array(
|
||||
'id' => $item->get_id(),
|
||||
'channel' => $item->get_type()->get_channel()->get_slug(),
|
||||
'title' => $item->get_title(),
|
||||
'manage_url' => $item->get_manage_url(),
|
||||
];
|
||||
);
|
||||
|
||||
if ( $item->get_cost() instanceof Price ) {
|
||||
$data['cost'] = [
|
||||
$data['cost'] = array(
|
||||
'value' => wc_format_decimal( $item->get_cost()->get_value() ),
|
||||
'currency' => $item->get_cost()->get_currency(),
|
||||
];
|
||||
);
|
||||
}
|
||||
|
||||
if ( $item->get_sales() instanceof Price ) {
|
||||
$data['sales'] = array(
|
||||
'value' => wc_format_decimal( $item->get_sales()->get_value() ),
|
||||
'currency' => $item->get_sales()->get_currency(),
|
||||
);
|
||||
}
|
||||
|
||||
$context = $request['context'] ?? 'view';
|
||||
@@ -168,55 +175,73 @@ class MarketingCampaigns extends WC_REST_Controller {
|
||||
* @return array Item schema data.
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = [
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'marketing_campaign',
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => [
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'The unique identifier for the marketing campaign.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
],
|
||||
'channel' => [
|
||||
),
|
||||
'channel' => array(
|
||||
'description' => __( 'The unique identifier for the marketing channel that this campaign belongs to.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
],
|
||||
'title' => [
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __( 'Title of the marketing campaign.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
],
|
||||
'manage_url' => [
|
||||
),
|
||||
'manage_url' => array(
|
||||
'description' => __( 'URL to the campaign management page.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
],
|
||||
'cost' => [
|
||||
),
|
||||
'cost' => array(
|
||||
'description' => __( 'Cost of the marketing campaign.', 'woocommerce' ),
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'value' => [
|
||||
'properties' => array(
|
||||
'value' => array(
|
||||
'type' => 'string',
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
],
|
||||
'currency' => [
|
||||
),
|
||||
'currency' => array(
|
||||
'type' => 'string',
|
||||
'context' => [ 'view' ],
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
),
|
||||
),
|
||||
),
|
||||
'sales' => array(
|
||||
'description' => __( 'Sales of the marketing campaign.', 'woocommerce' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'value' => array(
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'currency' => array(
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\API;
|
||||
|
||||
use Automattic\WooCommerce\Internal\Admin\Marketing\MarketingSpecs;
|
||||
use Automattic\WooCommerce\Admin\Features\MarketingRecommendations\Init as MarketingRecommendationsInit;
|
||||
use WC_REST_Controller;
|
||||
use WP_Error;
|
||||
use WP_REST_Request;
|
||||
@@ -88,18 +88,11 @@ class MarketingRecommendations extends WC_REST_Controller {
|
||||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
/**
|
||||
* MarketingSpecs class.
|
||||
*
|
||||
* @var MarketingSpecs $marketing_specs
|
||||
*/
|
||||
$marketing_specs = wc_get_container()->get( MarketingSpecs::class );
|
||||
|
||||
$category = $request->get_param( 'category' );
|
||||
if ( 'channels' === $category ) {
|
||||
$items = $marketing_specs->get_recommended_marketing_channels();
|
||||
$items = MarketingRecommendationsInit::get_recommended_marketing_channels();
|
||||
} elseif ( 'extensions' === $category ) {
|
||||
$items = $marketing_specs->get_recommended_marketing_extensions_excluding_channels();
|
||||
$items = MarketingRecommendationsInit::get_recommended_marketing_extensions_excluding_channels();
|
||||
} else {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_category', __( 'The specified category for recommendations is invalid. Allowed values: "channels", "extensions".', 'woocommerce' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* REST API Onboarding Themes Controller
|
||||
*
|
||||
* Handles requests to install and activate themes.
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\API;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\AIContent\UpdateProducts;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Onboarding Themes Controller.
|
||||
*
|
||||
* @internal
|
||||
* @extends WC_REST_Data_Controller
|
||||
*/
|
||||
class OnboardingProducts extends \WC_REST_Data_Controller {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc-admin';
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'onboarding';
|
||||
|
||||
/**
|
||||
* Register routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/products',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_products' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create products.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function create_products( $request ) {
|
||||
$update_products = new UpdateProducts();
|
||||
|
||||
$products = $update_products->fetch_dummy_products_to_update();
|
||||
|
||||
if ( is_wp_error( $products ) ) {
|
||||
return rest_ensure_response( array( 'success' => false ) );
|
||||
}
|
||||
|
||||
return rest_ensure_response( array( 'success' => true ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given request has access to manage themes.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot create dummy products.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -389,21 +389,6 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
|
||||
'sanitize_callback' => 'wp_parse_slug_list',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
'items' => array(
|
||||
'enum' => array(
|
||||
'jetpack',
|
||||
'jetpack-boost',
|
||||
'woocommerce-services',
|
||||
'woocommerce-payments',
|
||||
'mailchimp-for-woocommerce',
|
||||
'creative-mail-by-constant-contact',
|
||||
'facebook-for-woocommerce',
|
||||
'google-listings-and-ads',
|
||||
'pinterest-for-woocommerce',
|
||||
'mailpoet',
|
||||
'codistoconnect',
|
||||
'tiktok-for-business',
|
||||
'tiktok-for-business:alt',
|
||||
),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
|
||||
@@ -304,6 +304,10 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
||||
$cache_key = $this->get_cache_key( $query_args );
|
||||
$data = $this->get_cached_data( $cache_key );
|
||||
|
||||
if ( isset( $query_args['date_type'] ) ) {
|
||||
$this->date_column_name = $query_args['date_type'];
|
||||
}
|
||||
|
||||
if ( false === $data ) {
|
||||
$this->initialize_queries();
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class Controller extends GenericStatsController implements ExportableInterface {
|
||||
$args['segmentby'] = $request['segmentby'];
|
||||
$args['fields'] = $request['fields'];
|
||||
$args['force_cache_refresh'] = $request['force_cache_refresh'];
|
||||
$args['date_type'] = $request['date_type'];
|
||||
|
||||
return $args;
|
||||
}
|
||||
@@ -268,6 +269,16 @@ class Controller extends GenericStatsController implements ExportableInterface {
|
||||
),
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
);
|
||||
$params['date_type'] = array(
|
||||
'description' => __( 'Override the "woocommerce_date_type" option that is used for the database date field considered for revenue reports.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'enum' => array(
|
||||
'date_paid',
|
||||
'date_created',
|
||||
'date_completed',
|
||||
),
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user