-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Feature/network order widget #17598
Conversation
…r dashboard widget
…eds resolve even if a user doesn't have access to a site that we ask for
…o on-hold and processing statuses
…, so its always on any page with the widget
…no orders found" message
@cmmarslender is this issue ready for review? |
@claudiosanches yep |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@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! |
assets/js/admin/network-orders.js
Outdated
} | ||
|
||
var orders = [], | ||
promises = [], // Track completion (pass or fail) of ajax requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing period.
assets/js/admin/network-orders.js
Outdated
|
||
var orders = [], | ||
promises = [], // Track completion (pass or fail) of ajax requests | ||
deferred = [], // Tracks the ajax deferreds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing period.
assets/js/admin/network-orders.js
Outdated
$orderTable = $( document.getElementById( 'woocommerce-network-order-table' ) ), | ||
$noneFound = $( document.getElementById( 'woocommerce-network-orders-no-orders' ) ); | ||
|
||
// No sites, so bail |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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' ) ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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' ); ?> |
There was a problem hiding this comment.
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.
There was a problem hiding this 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' ), | |||
) ); | |||
|
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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() ); |
There was a problem hiding this comment.
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() ) ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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' ) ); |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
|
||
// Network Order Widget. | ||
if ( is_multisite() ) { | ||
wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
assets/css/admin.scss
Outdated
@@ -6234,3 +6234,25 @@ table.bar_chart { | |||
} | |||
} | |||
} | |||
|
|||
#woocommerce_network_orders { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed these.
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 |
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.
This branch relies on changes to styling from thetweak/order-screens
branch, so if you would like to test, things will look better if you test on thedemo
branch in my copy of the repo, which combines this branch with thetweak/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.