Merge remote-tracking branch 'origin/trunk' into update/marketplace-featured-page

This commit is contained in:
Timur Gogolev 2021-10-14 23:07:21 +03:00
commit 89a19c2544
12 changed files with 291 additions and 41 deletions

View File

@ -591,6 +591,18 @@
color: #50575e; /* Gray 60 */
}
}
.product-developed-by {
color: #50575e; // Gray 60
font-size: 12px;
font-family: sans-serif;
line-height: 20px;
margin-top: 4px;
.product-vendor-link {
color: #50575e; // Gray 60
}
}
}
.product-footer {
@ -607,7 +619,7 @@
}
.price-suffix {
color: #646970; /* Gray 50 */
color: #646970; // Gray 50
}
.product-reviews-block {
@ -636,8 +648,9 @@
}
.product-reviews-count {
color: #646970; /* Gray 50 */
color: #646970; // Gray 50
font-size: 12px;
font-family: sans-serif;
line-height: 24px;
letter-spacing: -0.154px;
margin-left: 4px;

View File

@ -997,6 +997,40 @@ class WC_Admin_Addons {
return " $admin_body_class woocommerce-page-wc-marketplace ";
}
/**
* Determine which class should be used for a rating star:
* - golden
* - half-filled (50/50 golden and gray)
* - gray
*
* Consider ratings from 3.0 to 4.0 as an example
* 3.0 will produce 3 stars
* 3.1 to 3.5 will produce 3 stars and a half star
* 3.6 to 4.0 will product 4 stars
*
* @param float $rating Rating of a product.
* @param int $index Index of a star in a row.
*
* @return string CSS class to use.
*/
public static function get_star_class( $rating, $index ) {
if ( $rating >= $index ) {
// Rating more that current star to show.
return 'fill';
} else if (
abs( $index - 1 - floor( $rating ) ) < 0.0000001 &&
0 < ( $rating - floor( $rating ) )
) {
// For rating more than x.0 and less than x.5 or equal it will show a half star.
return 50 >= floor( ( $rating - floor( $rating ) ) * 100 )
? 'half-fill'
: 'fill';
}
// Don't show a golden star otherwise.
return 'no-fill';
}
/**
* Take an action object and return the URL based on properties of the action.
*

View File

@ -63,4 +63,5 @@ if ( ! defined( 'ABSPATH' ) ) {
do_action( 'woocommerce_product_options_shipping' );
?>
</div>
<?php do_action( 'woocommerce_product_options_shipping_product_data' ); ?>
</div>

View File

@ -15,41 +15,6 @@ if ( ! defined( 'ABSPATH' ) ) {
}
$current_section_name = __( 'Browse Categories', 'woocommerce' );
/**
* Determine which class should be used for a rating star:
* - golden
* - half-filled (50/50 golden and gray)
* - gray
*
* Consider ratings from 3.0 to 4.0 as an example
* 3.0 will produce 3 stars
* 3.1 to 3.5 will produce 3 stars and a half star
* 3.6 to 4.0 will product 4 stars
*
* @param float $rating Rating of a product.
* @param int $index Index of a star in a row.
*
* @return string CSS class to use.
*/
function wccom_get_star_class( $rating, $index ) {
if ( $rating >= $index ) {
// Rating more that current star to show.
return 'fill';
} elseif (
abs( $index - 1 - floor( $rating ) ) < 0.0000001 &&
0 < ( $rating - floor( $rating ) )
) {
// For rating more than x.0 and less than x.5 or equal it will show a half star.
return 50 >= floor( ( $rating - floor( $rating ) ) * 100 )
? 'half-fill'
: 'fill';
}
// Don't show a golden star otherwise.
return 'no-fill';
}
?>
<div class="woocommerce wc-addons-wrap">
<h1 class="screen-reader-text"><?php esc_html_e( 'Marketplace', 'woocommerce' ); ?></h1>

View File

@ -166,6 +166,9 @@ class WC_Tracker {
// WooCommerce Admin info.
$data['wc_admin_disabled'] = apply_filters( 'woocommerce_admin_disabled', false ) ? 'yes' : 'no';
// Mobile info.
$data['wc_mobile_usage'] = self::get_woocommerce_mobile_usage();
return apply_filters( 'woocommerce_tracker_data', $data );
}
@ -756,6 +759,15 @@ class WC_Tracker {
'checkout_block_attributes' => $checkout_block_data['block_attributes'],
);
}
/**
* Get info about WooCommerce Mobile App usage
*
* @return array
*/
public static function get_woocommerce_mobile_usage() {
return get_option( 'woocommerce_mobile_app_usage' );
}
}
WC_Tracker::init();

View File

@ -0,0 +1,142 @@
<?php
/**
* REST API WC Telemetry controller
*
* Handles requests to the /wc-telemetry endpoint.
*
* @package WooCommerce\RestApi
* @since 3.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Telemetry controller class.
*
* @package WooCommerce\RestApi
* @extends WC_REST_Controller
*/
class WC_REST_Telemetry_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.
*
* @var string
*/
protected $namespace = 'wc-telemetry';
/**
* Route base.
*
* @var string
*/
protected $rest_base = 'tracker';
/**
* Register the route for /tracker
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'record_usage_data' ),
'permission_callback' => array( $this, 'telemetry_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}
/**
* Check whether a given request has permission to post telemetry data
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function telemetry_permissions_check( $request ) {
if ( ! is_user_logged_in() ) {
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you post telemetry data.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
/**
* Record WCTracker Data
*
* @param WP_REST_Request $request Full details about the request.
*/
public function record_usage_data( $request ) {
$new = $this->get_usage_data( $request );
if ( ! $new || ! $new['platform'] ) {
return;
}
$data = get_option( 'woocommerce_mobile_app_usage' );
if ( ! $data ) {
$data = array();
}
$platform = $new['platform'];
if ( ! $data[ $platform ] || version_compare( $new['version'], $data[ $platform ]['version'], '>=' ) ) {
$data[ $platform ] = $new;
}
update_option( 'woocommerce_mobile_app_usage', $data );
}
/**
* Get usage data from current request
*
* @param WP_REST_Request $request Full details about the request.
* @return Array
*/
public function get_usage_data( $request ) {
$platform = strtolower( $request->get_param( 'platform' ) );
switch ( $platform ) {
case 'ios':
case 'android':
break;
default:
return;
}
$version = $request->get_param( 'version' );
if ( ! $version ) {
return;
}
return array(
'platform' => sanitize_text_field( $platform ),
'version' => sanitize_text_field( $version ),
'last_used' => gmdate( 'c' ),
);
}
/**
* Get any query params needed.
*
* @return array
*/
public function get_collection_params() {
return array(
'platform' => array(
'description' => __( 'Platform to track.', 'woocommerce' ),
'required' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
),
'version' => array(
'description' => __( 'Platform version to track.', 'woocommerce' ),
'required' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
),
);
}
}

View File

@ -52,9 +52,10 @@ class Server {
return apply_filters(
'woocommerce_rest_api_get_rest_namespaces',
array(
'wc/v1' => $this->get_v1_controllers(),
'wc/v2' => $this->get_v2_controllers(),
'wc/v3' => $this->get_v3_controllers(),
'wc/v1' => $this->get_v1_controllers(),
'wc/v2' => $this->get_v2_controllers(),
'wc/v3' => $this->get_v3_controllers(),
'wc-telemetry' => $this->get_telemetry_controllers(),
)
);
}
@ -179,6 +180,17 @@ class Server {
);
}
/**
* List of controllers in the telemetry namespace.
*
* @return array
*/
protected function get_telemetry_controllers() {
return array(
'tracker' => 'WC_REST_Telemetry_Controller',
);
}
/**
* Return the path to the package.
*

View File

@ -0,0 +1,61 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests */
/**
* Internal dependencies
*/
const { HTTPClientFactory, Coupon } = require( '@woocommerce/api' );
/**
* External dependencies
*/
const config = require( 'config' );
const {
it,
describe,
beforeAll,
} = require( '@jest/globals' );
/**
* Create the default coupon and tests interactions with it via the API.
*/
const runTelemetryAPITest = () => {
describe( 'REST API > Telemetry', () => {
let client;
beforeAll(async () => {
const admin = config.get( 'users.admin' );
const url = config.get( 'url' );
client = HTTPClientFactory.build( url )
.withBasicAuth( admin.username, admin.password )
.withIndexPermalinks()
.create();
} );
it.each([
null,
{},
{ platform: 'ios' },
{ version: '1.1' },
])( 'errors for invalid request body - %p', async data => {
const response = await client
.post( `/wc-telemetry/tracker`, data )
.catch( err => {
expect( err.statusCode ).toBe( 400 );
} );
expect( response ).toBeUndefined();
} );
it( 'returns 200 with correct fields', async () => {
const response = await client
.post( `/wc-telemetry/tracker`, {
platform: 'ios',
version: '1.0',
})
expect( response.statusCode ).toBe( 200 );
} );
} );
};
module.exports = runTelemetryAPITest;

View File

@ -53,6 +53,7 @@ const runCouponApiTest = require( './api/coupon.test' );
const runGroupedProductAPITest = require( './api/grouped-product.test' );
const runVariableProductAPITest = require( './api/variable-product.test' );
const runOrderApiTest = require( './api/order.test' );
const runTelemetryAPITest = require( './api/telemetry.test' );
const runSetupOnboardingTests = () => {
runActivationTest();
@ -108,6 +109,7 @@ const runApiTests = () => {
runVariableProductAPITest();
runCouponApiTest();
runOrderApiTest();
runTelemetryAPITest();
}
module.exports = {
@ -160,4 +162,5 @@ module.exports = {
runMyAccountCreateAccountTest,
runOrderEmailReceivingTest,
runInitiateWccomConnectionTest,
runTelemetryAPITest,
};

2
tests/e2e/env/.env vendored
View File

@ -8,4 +8,4 @@ WORDPRESS_DEBUG=1
# WordPress CLI environment
WORDPRESS_HOST=wordpress-www:80
WORDPRESS_TITLE=WooCommerce Core E2E Test Suite
WORDPRESS_TITLE="WooCommerce Core E2E Test Suite"

View File

@ -2,6 +2,7 @@
## Added
- Added quotes around `WORDPRESS_TITLE` value in .env file to address issue with docker compose 2 "key cannot contain a space" error.
- Added `LATEST_WP_VERSION_MINUS` that allows setting a number to subtract from the current WordPress version for the WordPress Docker image.
# 0.2.3

View File

@ -0,0 +1,6 @@
/*
* Internal dependencies
*/
const { runTelemetryAPITest } = require( '@woocommerce/e2e-core-tests' );
runTelemetryAPITest();