Merge branch 'feature/network-order-widget' of https://github.com/cmmarslender/woocommerce into cmmarslender-feature/network-order-widget

This commit is contained in:
Claudio Sanches 2018-02-02 14:46:51 -02:00
commit 9c39dd34cc
14 changed files with 440 additions and 5 deletions

View File

@ -0,0 +1 @@
#woocommerce_network_orders .inside{margin:0;padding:0}#woocommerce_network_orders .woocommerce-network-order-table,#woocommerce_network_orders .woocommerce-network-order-table-loading,#woocommerce_network_orders .woocommerce-network-orders-no-orders{width:100%;display:none}#woocommerce_network_orders .woocommerce-network-order-table-loading.is-active,#woocommerce_network_orders .woocommerce-network-order-table.is-active,#woocommerce_network_orders .woocommerce-network-orders-no-orders.is-active{display:block}#woocommerce_network_orders .woocommerce-network-order-table-loading p,#woocommerce_network_orders .woocommerce-network-orders-no-orders p{text-align:center}#woocommerce_network_orders .woocommerce-network-order-table{margin-top:0}#woocommerce_network_orders .woocommerce-network-order-table.is-active{display:table}#woocommerce_network_orders .woocommerce-network-order-table thead td{padding:.5em 1em}#woocommerce_network_orders .spinner{margin-top:0;float:none}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td,#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody th{border-top:1px solid #f5f5f5}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td{vertical-align:middle;padding:1em}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;padding:0 1em;line-height:2.5em;color:#777;background:#e5e5e5;border-radius:4px;border-bottom:1px solid rgba(0,0,0,.05);margin:-.5em 0;cursor:inherit!important}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-completed{background:#c8d7e1;color:#2e4453}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-on-hold{background:#f8dda7;color:#94660c}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-failed{background:#eba3a3;color:#761919}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-processing{background:#c6e1c6;color:#5b841b}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-trash{background:#eba3a3;color:#761919}

View File

@ -0,0 +1 @@
#woocommerce_network_orders .inside{margin:0;padding:0}#woocommerce_network_orders .woocommerce-network-order-table,#woocommerce_network_orders .woocommerce-network-order-table-loading,#woocommerce_network_orders .woocommerce-network-orders-no-orders{width:100%;display:none}#woocommerce_network_orders .woocommerce-network-order-table-loading.is-active,#woocommerce_network_orders .woocommerce-network-order-table.is-active,#woocommerce_network_orders .woocommerce-network-orders-no-orders.is-active{display:block}#woocommerce_network_orders .woocommerce-network-order-table-loading p,#woocommerce_network_orders .woocommerce-network-orders-no-orders p{text-align:center}#woocommerce_network_orders .woocommerce-network-order-table{margin-top:0}#woocommerce_network_orders .woocommerce-network-order-table.is-active{display:table}#woocommerce_network_orders .woocommerce-network-order-table thead td{padding:.5em 1em}#woocommerce_network_orders .spinner{margin-top:0;float:none}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td,#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody th{border-top:1px solid #f5f5f5}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td{vertical-align:middle;padding:1em}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;padding:0 1em;line-height:2.5em;color:#777;background:#e5e5e5;border-radius:4px;border-bottom:1px solid rgba(0,0,0,.05);margin:-.5em 0;cursor:inherit!important}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-completed{background:#c8d7e1;color:#2e4453}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-on-hold{background:#f8dda7;color:#94660c}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-failed{background:#eba3a3;color:#761919}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-processing{background:#c6e1c6;color:#5b841b}#woocommerce_network_orders .post-type-shop_order .woocommerce-network-order-table tbody td .order-status.status-trash{background:#eba3a3;color:#761919}

View File

@ -0,0 +1,92 @@
#woocommerce_network_orders {
.inside {
margin: 0;
padding: 0;
}
.woocommerce-network-orders-no-orders,
.woocommerce-network-order-table-loading,
.woocommerce-network-order-table {
width: 100%;
display: none;
&.is-active {
display: block;
}
}
.woocommerce-network-orders-no-orders,
.woocommerce-network-order-table-loading {
p {
text-align: center;
}
}
.woocommerce-network-order-table {
&.is-active {
display: table;
}
margin-top: 0;
thead td {
padding: 0.5em 1em;
}
}
.spinner {
margin-top: 0;
float: none;
}
.post-type-shop_order {
.woocommerce-network-order-table {
tbody {
th, td {
border-top: 1px solid #f5f5f5;
}
td {
vertical-align: middle;
padding: 1em;
.order-status {
display: inline-flex;
padding: 0px 1em;
line-height: 2.5em;
color: #777;
background: #E5E5E5;
border-radius: 4px;
border-bottom: 1px solid rgba(0,0,0,0.05);
margin: -.5em 0;
cursor: inherit !important;
&.status-completed {
background: #C8D7E1;
color: #2e4453;
}
&.status-on-hold {
background: #f8dda7;
color: #94660c;
}
&.status-failed {
background: #eba3a3;
color: #761919;
}
&.status-processing {
background: #C6E1C6;
color: #5B841B;
}
&.status-trash {
background: #eba3a3;
color: #761919;
}
}
}
}
}
}
}

View File

@ -0,0 +1,90 @@
/*global woocommerce_network_orders */
(function( $, _, undefined ) {
if ( 'undefined' === typeof woocommerce_network_orders ) {
return;
}
var orders = [],
promises = [], // Track completion (pass or fail) of ajax requests.
deferred = [], // Tracks the ajax deferreds.
$tbody = $( document.getElementById( 'network-orders-tbody' ) ),
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' ) );
// No sites, so bail.
if ( ! woocommerce_network_orders.sites.length ) {
$loadingIndicator.removeClass( 'is-active' );
$orderTable.removeClass( 'is-active' );
$noneFound.addClass( 'is-active' );
return;
}
$.each( woocommerce_network_orders.sites, function( index, value ) {
promises[ index ] = $.Deferred();
deferred.push( $.ajax( {
url : woocommerce_network_orders.order_endpoint,
data: {
_wpnonce: woocommerce_network_orders.nonce,
network_orders: true,
blog_id: value
},
type: 'GET'
} ).success(function( response ) {
var orderindex;
for ( orderindex in response ) {
orders.push( response[ orderindex ] );
}
promises[ index ].resolve();
}).fail(function (){
promises[ index ].resolve();
}) );
} );
if ( promises.length > 0 ) {
$.when.apply( $, promises ).done( function() {
var orderindex,
currentOrder;
// Sort orders, newest first
orders.sort(function( a, b ) {
var adate, bdate;
adate = Date.parse( a.date_created_gmt );
bdate = Date.parse( b.date_created_gmt );
if ( adate === bdate ) {
return 0;
}
if ( adate < bdate ) {
return 1;
} else {
return -1;
}
});
if ( orders.length > 0 ) {
for ( orderindex in orders ) {
currentOrder = orders[ orderindex ];
$tbody.append( template( currentOrder ) );
}
$noneFound.removeClass( 'is-active' );
$loadingIndicator.removeClass( 'is-active' );
$orderTable.addClass( 'is-active' );
} else {
$noneFound.addClass( 'is-active' );
$loadingIndicator.removeClass( 'is-active' );
$orderTable.removeClass( 'is-active' );
}
} );
}
})( jQuery, _ );

1
assets/js/admin/network-orders.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(e,o,r){if("undefined"!=typeof woocommerce_network_orders){var t=[],n=[],s=[],a=e(document.getElementById("network-orders-tbody")),d=o.template(e(document.getElementById("network-orders-row-template")).text()),c=e(document.getElementById("woocommerce-network-order-table-loading")),i=e(document.getElementById("woocommerce-network-order-table")),m=e(document.getElementById("woocommerce-network-orders-no-orders"));if(!woocommerce_network_orders.sites.length)return c.removeClass("is-active"),i.removeClass("is-active"),void m.addClass("is-active");e.each(woocommerce_network_orders.sites,function(o,r){n[o]=e.Deferred(),s.push(e.ajax({url:woocommerce_network_orders.order_endpoint,data:{_wpnonce:woocommerce_network_orders.nonce,network_orders:!0,blog_id:r},type:"GET"}).success(function(e){var r;for(r in e)t.push(e[r]);n[o].resolve()}).fail(function(){n[o].resolve()}))}),n.length>0&&e.when.apply(e,n).done(function(){var e,o;if(t.sort(function(e,o){var r,t;return r=Date.parse(e.date_created_gmt),t=Date.parse(o.date_created_gmt),r===t?0:r<t?1:-1}),t.length>0){for(e in t)o=t[e],a.append(d(o));m.removeClass("is-active"),c.removeClass("is-active"),i.addClass("is-active")}else m.addClass("is-active"),c.removeClass("is-active"),i.removeClass("is-active")})}}(jQuery,_);

View File

@ -1 +1 @@
jQuery(function(e){e("table.widefat.wp-list-table tr").append('<td class="column-handle"></td>'),e("table.widefat.wp-list-table").sortable({items:"tbody tr:not(.inline-edit-row)",cursor:"move",handle:".column-handle",axis:"y",forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"product-cat-placeholder",scrollSensitivity:40,start:function(e,t){t.item.hasClass("alternate")||t.item.css("background-color","#ffffff"),t.item.children("td, th").css("border-bottom-width","0"),t.item.css("outline","1px solid #aaa")},stop:function(e,t){t.item.removeAttr("style"),t.item.children("td, th").css("border-bottom-width","1px")},update:function(t,i){var n,a,d=i.item.find(".check-column input").val(),o=i.item.find(".parent").html(),l=i.item.prev().find(".check-column input").val(),r=i.item.next().find(".check-column input").val();l!==undefined&&(n=i.item.prev().find(".parent").html())!==o&&(l=undefined),r!==undefined&&(a=i.item.next().find(".parent").html())!==o&&(r=undefined),l===undefined&&r===undefined||r===undefined&&a===l||r!==undefined&&n===d?e("table.widefat.wp-list-table").sortable("cancel"):(i.item.find(".check-column input").hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),e.post(ajaxurl,{action:"woocommerce_term_ordering",id:d,nextid:r,thetaxonomy:woocommerce_term_ordering_params.taxonomy},function(e){"children"===e?window.location.reload():i.item.find(".check-column input").show().siblings("img").remove()}),e("table.widefat tbody tr").each(function(){jQuery("table.widefat tbody tr").index(this)%2==0?jQuery(this).addClass("alternate"):jQuery(this).removeClass("alternate")}))}})});
jQuery(function(e){var t='.column-handle input[name="term_id"]';0===e("table.wp-list-table").find(".column-handle").length&&(e("table.wp-list-table").find("tr:not(.inline-edit-row)").append('<td class="column-handle"></td>'),t=".check-column input"),e("table.wp-list-table").find(".column-handle").show(),e("table.wp-list-table").sortable({items:"tbody tr:not(.inline-edit-row)",cursor:"move",handle:".column-handle",axis:"y",forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"product-cat-placeholder",scrollSensitivity:40,start:function(e,t){t.item.hasClass("alternate")||t.item.css("background-color","#ffffff"),t.item.children("td, th").css("border-bottom-width","0"),t.item.css("outline","1px solid #aaa")},stop:function(e,t){t.item.removeAttr("style"),t.item.children("td, th").css("border-bottom-width","1px")},update:function(n,i){var l,d,a=i.item.find(t).val(),o=i.item.find(".parent").html(),r=i.item.prev().find(t).val(),c=i.item.next().find(t).val();r!==undefined&&(l=i.item.prev().find(".parent").html())!==o&&(r=undefined),c!==undefined&&(d=i.item.next().find(".parent").html())!==o&&(c=undefined),r===undefined&&c===undefined||c===undefined&&d===r||c!==undefined&&l===a?e("table.wp-list-table").sortable("cancel"):(i.item.find(".check-column input").hide(),i.item.find(".check-column").append('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),e.post(ajaxurl,{action:"woocommerce_term_ordering",id:a,nextid:c,thetaxonomy:woocommerce_term_ordering_params.taxonomy},function(e){"children"===e?window.location.reload():(i.item.find(".check-column input").show(),i.item.find(".check-column").find("img").remove())}),e("table.widefat tbody tr").each(function(){jQuery("table.widefat tbody tr").index(this)%2==0?jQuery(this).addClass("alternate"):jQuery(this).removeClass("alternate")}))}})});

View File

@ -1 +1 @@
jQuery(function(e){if("undefined"==typeof wc_orders_params)return!1;var r=function(){e(document).on("click",".post-type-shop_order .wp-list-table tbody td",this.onRowClick).on("click",".order-preview:not(.disabled)",this.onPreview)};r.prototype.onRowClick=function(r){if(e(r.target).filter("a").length)return!0;var a=e(this).closest("tr").find("a.order-view").attr("href");a.length&&(r.preventDefault(),r.metaKey?window.open(a,"_blank"):window.location=a)},r.prototype.onPreview=function(){var r=e(this),a=r.data("order-id");return r.data("order-data")?e(this).WCBackboneModal({template:"wc-modal-view-order",variable:r.data("order-data")}):(r.addClass("disabled"),e.ajax({url:wc_orders_params.ajax_url,data:{order_id:a,action:"woocommerce_get_order_details",security:wc_orders_params.preview_nonce},type:"GET",success:function(a){e(".order-preview").removeClass("disabled"),a.success&&(r.data("order-data",a.data),e(this).WCBackboneModal({template:"wc-modal-view-order",variable:a.data}))}})),!1},new r});
jQuery(function(e){if("undefined"==typeof wc_orders_params)return!1;var r=function(){e(document).on("click",".post-type-shop_order .wp-list-table tbody td",this.onRowClick).on("click",".order-preview:not(.disabled)",this.onPreview)};r.prototype.onRowClick=function(r){if(e(r.target).filter("a, a *, .no-link, .no-link *").length)return!0;var a=e(this).closest("tr").find("a.order-view").attr("href");a.length&&(r.preventDefault(),r.metaKey||r.ctrlKey?window.open(a,"_blank"):window.location=a)},r.prototype.onPreview=function(){var r=e(this),a=r.data("order-id");return r.data("order-data")?e(this).WCBackboneModal({template:"wc-modal-view-order",variable:r.data("order-data")}):(r.addClass("disabled"),e.ajax({url:wc_orders_params.ajax_url,data:{order_id:a,action:"woocommerce_get_order_details",security:wc_orders_params.preview_nonce},type:"GET",success:function(a){e(".order-preview").removeClass("disabled"),a.success&&(r.data("order-data",a.data),e(this).WCBackboneModal({template:"wc-modal-view-order",variable:a.data}))}})),!1},new r});

View File

@ -1 +1 @@
jQuery(function(e){function i(){e(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}function s(){e("form.activate-jetpack").submit()}function t(){wp.ajax.post("setup_wizard_check_jetpack").then(function(e){if(!e||!e.is_active||"yes"===e.is_active)return s();setTimeout(t,3e3)}).fail(function(){s()})}e(".button-next").on("click",function(){var s=e(this).parents("form").get(0);return("function"!=typeof s.checkValidity||s.checkValidity())&&i(),!0}),e(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-toggle").removeClass("disabled"),e(this).closest(".wc-wizard-service-item").addClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").removeClass("hide")):(e(this).closest(".wc-wizard-service-toggle").addClass("disabled"),e(this).closest(".wc-wizard-service-item").removeClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").addClass("hide"))}),e(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(i){if(e(i.target).is("input"))i.stopPropagation();else{var s=e(this).find('input[type="checkbox"]');s.prop("checked",!s.prop("checked")).change()}}),e(".wc-wizard-services-list-toggle").on("change",".wc-wizard-service-enable input",function(){e(this).closest(".wc-wizard-services-list-toggle").toggleClass("closed"),e(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")}),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-select .method",function(i){var s=e(this).closest(".wc-wizard-service-description"),t=i.target.value,c=s.find(".shipping-method-descriptions");c.find(".shipping-method-description").addClass("hide"),c.find("."+t).removeClass("hide");var r=s.find(".shipping-method-settings");r.find(".shipping-method-setting").addClass("hide").find(".shipping-method-required-field").prop("required",!1),r.find("."+t).removeClass("hide").find(".shipping-method-required-field").prop("required",!0)}),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-enable",function(){var i=e(this).is(":checked");e(this).closest(".wc-wizard-service-item").find(".shipping-method-required-field").prop("required",i)}),e(".activate-jetpack").on("click",".button-primary",function(e){if(i(),"no"===wc_setup_params.pending_jetpack_install)return!0;e.preventDefault(),t()}),e(".wc-wizard-services").on("change","input#stripe_create_account, input#ppec_paypal_reroute_requests",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!0),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").show()):(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!1),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").hide())}).find("input#stripe_create_account, input#ppec_paypal_reroute_requests").change(),e("select#store_country_state").on("change",function(){var i=this.value.split(":")[0];e("select#currency_code").val(wc_setup_currencies[i]).change()})});
jQuery(function(e){function i(){e(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}function s(){e("form.activate-jetpack").submit()}function t(){wp.ajax.post("setup_wizard_check_jetpack").then(function(e){if(!e||!e.is_active||"yes"===e.is_active)return s();setTimeout(t,3e3)}).fail(function(){s()})}e(".button-next").on("click",function(){var s=e(this).parents("form").get(0);return("function"!=typeof s.checkValidity||s.checkValidity())&&i(),!0}),e(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-toggle").removeClass("disabled"),e(this).closest(".wc-wizard-service-item").addClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").removeClass("hide")):(e(this).closest(".wc-wizard-service-toggle").addClass("disabled"),e(this).closest(".wc-wizard-service-item").removeClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").addClass("hide"))}),e(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(i){if(e(i.target).is("input"))i.stopPropagation();else{var s=e(this).find('input[type="checkbox"]');s.prop("checked",!s.prop("checked")).change()}}),e(".wc-wizard-services-list-toggle").on("change",".wc-wizard-service-enable input",function(){e(this).closest(".wc-wizard-services-list-toggle").toggleClass("closed"),e(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")}),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-select .method",function(i){var s=e(this).closest(".wc-wizard-service-description"),t=i.target.value,c=s.find(".shipping-method-descriptions");c.find(".shipping-method-description").addClass("hide"),c.find("."+t).removeClass("hide");var r=s.find(".shipping-method-settings");r.find(".shipping-method-setting").addClass("hide").find(".shipping-method-required-field").prop("required",!1),r.find("."+t).removeClass("hide").find(".shipping-method-required-field").prop("required",!0)}).find(".wc-wizard-shipping-method-select .method").change(),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-enable",function(){var i=e(this).is(":checked");e(this).closest(".wc-wizard-service-item").find(".shipping-method-required-field").prop("required",i)}),e(".activate-jetpack").on("click",".button-primary",function(e){if(i(),"no"===wc_setup_params.pending_jetpack_install)return!0;e.preventDefault(),t()}),e(".wc-wizard-services").on("change","input#stripe_create_account, input#ppec_paypal_reroute_requests",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!0),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").show()):(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!1),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").hide())}).find("input#stripe_create_account, input#ppec_paypal_reroute_requests").change(),e("select#store_country_state").on("change",function(){var i=this.value.split(":")[0];e("select#currency_code").val(wc_setup_currencies[i]).change()})});

View File

@ -1 +1 @@
jQuery(function(e){function t(){o&&sessionStorage.setItem("wc_cart_created",(new Date).getTime())}function n(e){o&&(localStorage.setItem(a,e),sessionStorage.setItem(a,e))}function r(){e.ajax(s)}if("undefined"==typeof wc_cart_fragments_params)return!1;var o=!0,a=wc_cart_fragments_params.cart_hash_key;try{o="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc"),window.localStorage.setItem("wc","test"),window.localStorage.removeItem("wc")}catch(w){o=!1}var s={url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_refreshed_fragments"),type:"POST",success:function(r){r&&r.fragments&&(e.each(r.fragments,function(t,n){e(t).replaceWith(n)}),o&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(r.fragments)),n(r.cart_hash),r.cart_hash&&t()),e(document.body).trigger("wc_fragments_refreshed"))}};if(o){var i=null;e(document.body).on("wc_fragment_refresh updated_wc_div",function(){r()}),e(document.body).on("added_to_cart",function(e,r,o){var s=sessionStorage.getItem(a);null!==s&&s!==undefined&&""!==s||t(),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(r)),n(o)}),e(document.body).on("wc_fragments_refreshed",function(){clearTimeout(i),i=setTimeout(r,864e5)}),e(window).on("storage onstorage",function(e){a===e.originalEvent.key&&localStorage.getItem(a)!==sessionStorage.getItem(a)&&r()}),e(window).on("pageshow",function(t){t.originalEvent.persisted&&(e(".widget_shopping_cart_content").empty(),e(document.body).trigger("wc_fragment_refresh"))});try{var c=e.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),_=sessionStorage.getItem(a),g=Cookies.get("woocommerce_cart_hash"),m=sessionStorage.getItem("wc_cart_created");if(null!==_&&_!==undefined&&""!==_||(_=""),null!==g&&g!==undefined&&""!==g||(g=""),_&&(null===m||m===undefined||""===m))throw"No cart_created";if(m){var d=1*m+864e5,f=(new Date).getTime();if(d<f)throw"Fragment expired";i=setTimeout(r,d-f)}if(!c||!c["div.widget_shopping_cart_content"]||_!==g)throw"No fragment";e.each(c,function(t,n){e(t).replaceWith(n)}),e(document.body).trigger("wc_fragments_loaded")}catch(w){r()}}else r();Cookies.get("woocommerce_items_in_cart")>0?e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),e(document.body).on("adding_to_cart",function(){e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()})});
jQuery(function(e){function t(){o&&sessionStorage.setItem("wc_cart_created",(new Date).getTime())}function n(e){o&&(localStorage.setItem(a,e),sessionStorage.setItem(a,e))}function r(){e.ajax(s)}if("undefined"==typeof wc_cart_fragments_params)return!1;var o=!0,a=wc_cart_fragments_params.cart_hash_key;try{o="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc"),window.localStorage.setItem("wc","test"),window.localStorage.removeItem("wc")}catch(w){o=!1}var s={url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_refreshed_fragments"),type:"POST",success:function(r){r&&r.fragments&&(e.each(r.fragments,function(t,n){e(t).replaceWith(n)}),o&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(r.fragments)),n(r.cart_hash),r.cart_hash&&t()),e(document.body).trigger("wc_fragments_refreshed"))}};if(o){var i=null;e(document.body).on("wc_fragment_refresh updated_wc_div",function(){r()}),e(document.body).on("added_to_cart removed_from_cart",function(e,r,o){var s=sessionStorage.getItem(a);null!==s&&s!==undefined&&""!==s||t(),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(r)),n(o)}),e(document.body).on("wc_fragments_refreshed",function(){clearTimeout(i),i=setTimeout(r,864e5)}),e(window).on("storage onstorage",function(e){a===e.originalEvent.key&&localStorage.getItem(a)!==sessionStorage.getItem(a)&&r()}),e(window).on("pageshow",function(t){t.originalEvent.persisted&&(e(".widget_shopping_cart_content").empty(),e(document.body).trigger("wc_fragment_refresh"))});try{var c=e.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),_=sessionStorage.getItem(a),g=Cookies.get("woocommerce_cart_hash"),m=sessionStorage.getItem("wc_cart_created");if(null!==_&&_!==undefined&&""!==_||(_=""),null!==g&&g!==undefined&&""!==g||(g=""),_&&(null===m||m===undefined||""===m))throw"No cart_created";if(m){var d=1*m+864e5,f=(new Date).getTime();if(d<f)throw"Fragment expired";i=setTimeout(r,d-f)}if(!c||!c["div.widget_shopping_cart_content"]||_!==g)throw"No fragment";e.each(c,function(t,n){e(t).replaceWith(n)}),e(document.body).trigger("wc_fragments_loaded")}catch(w){r()}}else r();Cookies.get("woocommerce_items_in_cart")>0?e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),e(document.body).on("adding_to_cart",function(){e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()})});

View File

@ -25,7 +25,12 @@ class WC_Admin_Dashboard {
public function __construct() {
// Only hook in admin parts if the user has admin access
if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
// If on network admin, only load the widget that works in that context and skip the rest.
if ( is_multisite() && is_network_admin() ) {
add_action( 'wp_network_dashboard_setup', array( $this, 'register_network_order_widget' ) );
} else {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
}
}
}
@ -37,6 +42,18 @@ class WC_Admin_Dashboard {
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.
if ( is_multisite() ) {
$this->register_network_order_widget();
}
}
/**
* Register the network order dashboard widget.
*/
public function register_network_order_widget() {
wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) );
}
/**
@ -286,6 +303,72 @@ class WC_Admin_Dashboard {
echo '<p>' . __( 'There are no product reviews yet.', 'woocommerce' ) . '</p>';
}
}
/**
* Network orders widget.
*/
public function network_orders() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION );
wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true );
$user = wp_get_current_user();
$blogs = get_blogs_of_user( $user->ID );
$blog_ids = wp_list_pluck( $blogs, 'userblog_id' );
wp_localize_script( 'wc-network-orders', 'woocommerce_network_orders', array(
'nonce' => wp_create_nonce( 'wp_rest' ),
'sites' => array_values( $blog_ids ),
'order_endpoint' => get_rest_url( null, 'wc/v2/orders/network' ),
) );
?>
<div class="post-type-shop_order">
<div id="woocommerce-network-order-table-loading" class="woocommerce-network-order-table-loading is-active">
<p>
<span class="spinner is-active"></span> <?php esc_html_e( 'Loading network orders', 'woocommerce' ); ?>
</p>
</div>
<table id="woocommerce-network-order-table" class="woocommerce-network-order-table">
<thead>
<tr>
<td><?php esc_html_e( 'Order', 'woocommerce' ); ?></td>
<td><?php esc_html_e( 'Status', 'woocommerce' ); ?></td>
<td><?php esc_html_e( 'Total', 'woocommerce' ); ?></td>
</tr>
</thead>
<tbody id="network-orders-tbody">
</tbody>
</table>
<div id="woocommerce-network-orders-no-orders" class="woocommerce-network-orders-no-orders">
<p>
<?php esc_html_e( 'No orders found', 'woocommerce' ); ?>
</p>
</div>
<script type="text/template" id="network-orders-row-template">
<tr>
<td>
<a href="<%- edit_url %>" class="order-view"><strong>#<%- id %> <%- customer %></strong></a>
<br>
<em>
<%- blog.blogname %>
</em>
</td>
<td>
<mark class="order-status status-<%- status %>"><span><%- status_name %></span></mark>
</td>
<td>
<%= formatted_total %>
</td>
</tr>
</script>
</div>
<?php
}
}
endif;

View File

@ -96,6 +96,7 @@ class WC_Admin {
switch ( $screen->id ) {
case 'dashboard' :
case 'dashboard-network' :
include( 'class-wc-admin-dashboard.php' );
break;
case 'options-permalink' :

View File

@ -0,0 +1,154 @@
<?php
/**
* REST API Network Orders controller
*
* Handles requests to the /orders/network endpoint
*
* @author WooThemes
* @category API
* @package WooCommerce/API
* @since 3.3
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* REST API Network Orders controller class.
*
* @package WooCommerce/API
* @extends WC_REST_Orders_Controller
*/
class WC_REST_Network_Orders_Controller extends WC_REST_Orders_Controller {
/**
* Register the routes for network orders.
*/
public function register_routes() {
if ( is_multisite() ) {
register_rest_route( $this->namespace, '/' . $this->rest_base . '/network', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'network_orders' ),
'permission_callback' => array( $this, 'network_orders_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
}
}
/**
* Retrieves the item's schema for display / public consumption purposes.
*
* @access public
*
* @return array Public item schema data.
*/
public function get_public_item_schema() {
$schema = parent::get_public_item_schema();
$schema['properties']['blog'] = array(
'description' => __( 'Blog id of the record on the multisite.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view' ),
'readonly' => true,
);
$schema['properties']['edit_url'] = array(
'description' => __( 'URL to edit the order', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view' ),
'readonly' => true,
);
$schema['properties']['customer'][] = array(
'description' => __( 'Name of the customer for the order', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view' ),
'readonly' => true,
);
$schema['properties']['status_name'][] = array(
'description' => __( 'Order Status', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view' ),
'readonly' => true,
);
$schema['properties']['formatted_total'][] = array(
'description' => __( 'Order total formatted for locale', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view' ),
'readonly' => true,
);
return $schema;
}
/**
* Does a permissions check for the proper requested blog
*
* @param WP_REST_Request $request Full details about the request.
*
* @return bool $permission
*/
public function network_orders_permissions_check( $request ) {
$blog_id = $request->get_param( 'blog_id' );
$blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id();
switch_to_blog( $blog_id );
$permission = $this->get_items_permissions_check( $request );
restore_current_blog();
return $permission;
}
/**
* Get a collection of orders from the requested blog id
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_REST_Response
*/
public function network_orders( $request ) {
$blog_id = $request->get_param( 'blog_id' );
$blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id();
switch_to_blog( $blog_id );
add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) );
$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 ) {
$order = wc_get_order( $current_order['id'] );
$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' );
/* translators: 1: first name 2: last name */
$current_order['customer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
$current_order['status_name'] = wc_get_order_status_name( $order->get_status() );
$current_order['formatted_total'] = $order->get_formatted_order_total();
}
restore_current_blog();
return $items;
}
/**
* Filters the post statuses to on hold and processing for the network order query.
*
* @param array $args Query args.
*
* @return array
*/
public function network_orders_filter_args( $args ) {
$args['post_status'] = array(
'wc-on-hold',
'wc-processing',
);
return $args;
}
}

View File

@ -391,6 +391,16 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
}
}
/**
* Filter the query arguments for a request.
*
* Enables adding extra arguments or setting defaults for an order collection request.
*
* @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 );
return $args;
}

View File

@ -175,6 +175,7 @@ class WC_API extends WC_Legacy_API {
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-customer-downloads-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-customers-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-orders-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-network-orders-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-order-notes-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-order-refunds-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-product-attribute-terms-controller.php' );
@ -239,6 +240,7 @@ class WC_API extends WC_Legacy_API {
'WC_REST_Coupons_Controller',
'WC_REST_Customer_Downloads_Controller',
'WC_REST_Customers_Controller',
'WC_REST_Network_Orders_Controller',
'WC_REST_Order_Notes_Controller',
'WC_REST_Order_Refunds_Controller',
'WC_REST_Orders_Controller',