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

Feature/network order widget #17598

Merged
merged 32 commits into from
Feb 2, 2018
Merged

Feature/network order widget #17598

merged 32 commits into from
Feb 2, 2018

Conversation

cmmarslender
Copy link
Contributor

@cmmarslender cmmarslender commented Nov 6, 2017

Adds a dashboard widget on multisite installs that shows orders that need an action from across the multisite, from any site the user has access to orders on.

screenshot

This branch relies on changes to styling from the tweak/order-screens branch, so if you would like to test, things will look better if you test on the demo branch in my copy of the repo, which combines this branch with the tweak/order-screens branch.

The styling changes this relied on are now merged into master so no special branch is needed for testing.

To test, you need to have a multisite installation of WordPress with WooCommerce installed. Since the widget is only designed to show orders that are processing or on hold, you'll need orders with this status on at least one of the sites you would like to see order data from. The user you test with will also need to have access to the site (and appropriate permissions to see order data) or the orders will not show up.

@claudiosanches
Copy link
Contributor

@cmmarslender is this issue ready for review?

@cmmarslender
Copy link
Contributor Author

@claudiosanches yep

@codecov
Copy link

codecov bot commented Nov 6, 2017

Codecov Report

Merging #17598 into master will decrease coverage by 0.07%.
The diff coverage is 3.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #17598      +/-   ##
============================================
- Coverage      34.8%   34.73%   -0.08%     
- Complexity    12370    12387      +17     
============================================
  Files           342      343       +1     
  Lines         50725    50839     +114     
============================================
+ Hits          17655    17658       +3     
- Misses        33070    33181     +111
Impacted Files Coverage Δ Complexity Δ
includes/class-wc-api.php 20% <0%> (-0.18%) 15 <0> (ø)
includes/admin/class-wc-admin-dashboard.php 0% <0%> (ø) 33 <4> (+7) ⬆️
includes/admin/class-wc-admin.php 0% <0%> (ø) 49 <0> (+1) ⬆️
includes/api/class-wc-rest-orders-controller.php 88.8% <100%> (+0.01%) 127 <0> (ø) ⬇️
...es/api/class-wc-rest-network-orders-controller.php 5.66% <5.66%> (ø) 9 <9> (?)
includes/class-wc-tax.php 80.05% <0%> (-0.26%) 136% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a98c494...81d1136. Read the comment docs.

@mikejolley
Copy link
Member

@cmmarslender Not had a chance to review this yet, but it would be good if you could include a short description in the PR as well as testing instructions should someone want to check this out or test :) Thanks!

}

var orders = [],
promises = [], // Track completion (pass or fail) of ajax requests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period.


var orders = [],
promises = [], // Track completion (pass or fail) of ajax requests
deferred = [], // Tracks the ajax deferreds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period.

$orderTable = $( document.getElementById( 'woocommerce-network-order-table' ) ),
$noneFound = $( document.getElementById( 'woocommerce-network-orders-no-orders' ) );

// No sites, so bail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period.

@@ -37,6 +37,11 @@ public function init() {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce recent reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) );
}
wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce status', 'woocommerce' ), array( $this, 'status_widget' ) );

// Network Order Widget
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period.


// Network Order Widget
if ( is_multisite() ) {
wp_add_dashboard_widget( 'woocommerce_network_orders', __( "WooCommerce Network Orders", 'woocommerce' ), array( $this, 'network_orders' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for double quotes here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are avoiding title case in WooCommerce, so this name need to be fixed.

@@ -286,6 +291,70 @@ public function recent_reviews() {
echo '<p>' . __( 'There are no product reviews yet.', 'woocommerce' ) . '</p>';
}
}

/**
* Network orders widget
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period.

<table id="woocommerce-network-order-table" class="woocommerce-network-order-table wp-list-table">
<thead>
<tr>
<td>Order</td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this strings need to be translatable.

</table>
<div id="woocommerce-network-orders-no-orders" class="woocommerce-network-orders-no-orders">
<p>
<?php esc_html_e( "No orders found", 'woocommerce' ); ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for double quote.

Copy link
Contributor

@claudiosanches claudiosanches left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor coding standards to fix, but the endpoint should be moved into a new class, since the schema includes a few new items.

@@ -121,6 +121,18 @@ public function register_routes() {
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes should be moved into a new class, creating a new schema too, since includes new items to the current orders schema.

$items = $this->get_items( $request );
remove_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) );

foreach( $items->data as &$current_order ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after foreach.

foreach( $items->data as &$current_order ) {
$order = wc_get_order( $current_order['id'] );

$current_order['blog'] = get_blog_details( get_current_blog_id() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This items included here that need to belong the schema and that's why will be better have a new class just for it.


$current_order['blog'] = get_blog_details( get_current_blog_id() );
$current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' );
$current_order['buyer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing /* translators */ comment to help translators with placeholders.

* @param array $args Key value array of query var to query value.
* @param WP_REST_Request $request The request used.
*/
$args = apply_filters( "woocommerce_rest_orders_prepare_object_query", $args, $request );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for double quotes here.

@claudiosanches claudiosanches added the needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. label Nov 9, 2017
Copy link
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job :) Added some feedback. I tested on a simply multisite and it worked first time on all subsites.

template = _.template( $( document.getElementById( 'network-orders-row-template') ).text() ),
$loadingIndicator = $( document.getElementById( 'woocommerce-network-order-table-loading' ) ),
$orderTable = $( document.getElementById( 'woocommerce-network-order-table' ) ),
$noneFound = $( document.getElementById( 'woocommerce-network-orders-no-orders' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for using ID rather than jQuery based selectors? You have class and ID set in the markup - just asking :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikejolley Class was set to enable styling that wasn't too specific.

getElementById was used for performance reasons over the jQuery selectors. document.getElementsByClassName is faster than getElementById, but isn't supported on as many browsers (IE11+) whereas getElementById is supported on basically all browsers even back to IE6. jQuery selectors are slower than all of the above options.

Perf Test


// Network Order Widget.
if ( is_multisite() ) {
wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a case where WC is network activated, would this also work on the network dashboard without other changes? If so, it might be a quick nice addition. Just need to use the hook wp_network_dashboard_setup too. No biggy if that won't work.

public function network_orders() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';

wp_enqueue_script( 'network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we prefix the script handle with wc-.

@@ -39,6 +39,7 @@ function wc_get_screen_ids() {
'edit-product_tag',
'profile',
'user-edit',
'dashboard',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including this on the dashboard would work, but it will also add extra overhead from WC scripts and styles, and potentially introduce conflicts. It isn't ideal, but can we move the CSS needed in this widget to a stylesheet only used on dashboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, yes. In addition to the styles I've added, I'll also have to take some styles from your redesign of the order listing page, and include those as well, so there would be a bit of duplication.. Sound ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats probably better than loading them all in and you can target the widget only.

* @author WooThemes
* @category API
* @package WooCommerce/API
* @since @todo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claudiulodro 3.3 or 3.4?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.3 is good. This just has small changes left.

* @package WooCommerce/API
* @extends WC_REST_Orders_Controller
*/
class WC_REST_Network_Orders_Controller extends WC_REST_Orders_Controller {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claudiosanches Are you happy for this to be added in v2 api or should we punt the feature until v3 api is introduced? It's more of an internal API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very small and for internal use, we could include and not even include into the docs for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to mention that v3 will take a long time to be released, there is a lot of work there and things to be reviewed.

'context' => array( 'view' ),
'readonly' => true,
);
$schema['properties']['buyer'][] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customer more appropriate? It's the language used everywhere else.

* @return array
*/
public function network_orders_filter_args( $args ) {
$args['post_status'] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we allowed this to be passed in as an arg to the API, the widget could be improved in the future to allow status filtering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about this, and originally decided to keep it simple, and not open up the endpoint (for now) to more use cases than I needed. I can update this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I did try and implement this initially, but ran into a case where the current API only supports one status - see here

In order to change to allowing multiple statuses, the args for the endpoint would need to be changed to type => array. I didn't make this change because I didn't want to potentially break or change existing API functionality.

You mentioned there is a v3 of the API in the works - Possibly target array support for status on the V3 api instead of just a single string value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup good call. I've logged separately. woocommerce/wc-api-dev#73

@@ -6234,3 +6234,25 @@ table.bar_chart {
}
}
}

#woocommerce_network_orders {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styling issues:

  • Table within widget is not 100% width
  • TH padding is misaligned with TDs
  • Could use some negative margin, or lose the padding on .inside` so the table appears full width and more closely matches other widgets.
  • Row has cursor pointer, but is not really clickable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed these.

@mikejolley mikejolley added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed Status: Needs Review labels Nov 17, 2017
@mikejolley mikejolley added Status: Needs Review and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Nov 20, 2017
@claudiulodro claudiulodro added this to the 3.4.0 milestone Nov 20, 2017
@mikejolley
Copy link
Member

I think this is good to go 👍 We're going to keep this back for WC 3.4 next year rather than push to 3.3 release. Good to have features in the bag ready for releases :)

Thanks again

@mikejolley mikejolley added Release: Minor status: blocked The issue is blocked from progressing, waiting for another piece of work to be done. and removed Status: Needs Review labels Nov 21, 2017
@mikejolley mikejolley removed the status: blocked The issue is blocked from progressing, waiting for another piece of work to be done. label Jan 29, 2018
@claudiosanches claudiosanches merged commit 81d1136 into woocommerce:master Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants