Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Diego Zanella 2015-06-10 19:13:33 +01:00
commit f44741540f
76 changed files with 2231 additions and 591 deletions

View File

@ -19,6 +19,7 @@
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false
}
}

View File

@ -62,6 +62,7 @@ module.exports = function( grunt ) {
'<%= dirs.js %>/jquery-blockui/jquery.blockUI.min.js': ['<%= dirs.js %>/jquery-blockui/jquery.blockUI.js'],
'<%= dirs.js %>/jquery-cookie/jquery.cookie.min.js': ['<%= dirs.js %>/jquery-cookie/jquery.cookie.js'],
'<%= dirs.js %>/jquery-payment/jquery.payment.min.js': ['<%= dirs.js %>/jquery-payment/jquery.payment.js'],
'<%= dirs.js %>/jquery-qrcode/jquery.qrcode.min.js': ['<%= dirs.js %>/jquery-qrcode/jquery.qrcode.js'],
'<%= dirs.js %>/jquery-tiptip/jquery.tipTip.min.js': ['<%= dirs.js %>/jquery-tiptip/jquery.tipTip.js'],
'<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.init.min.js': ['<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.init.js'],
'<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.min.js': ['<%= dirs.js %>/prettyPhoto/jquery.prettyPhoto.js'],

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
@charset "UTF-8";@font-face{font-family:star;src:url(../fonts/star.eot);src:url(../fonts/star.eot?#iefix) format("embedded-opentype"),url(../fonts/star.woff) format("woff"),url(../fonts/star.ttf) format("truetype"),url(../fonts/star.svg#star) format("svg");font-weight:400;font-style:normal}@font-face{font-family:WooCommerce;src:url(../fonts/WooCommerce.eot);src:url(../fonts/WooCommerce.eot?#iefix) format("embedded-opentype"),url(../fonts/WooCommerce.woff) format("woff"),url(../fonts/WooCommerce.ttf) format("truetype"),url(../fonts/WooCommerce.svg#WooCommerce) format("svg");font-weight:400;font-style:normal}ul.woocommerce_stats{overflow:hidden;zoom:1}ul.woocommerce_stats li{width:25%;padding:0 1em;float:left;font-size:.8em;border-left:1px solid #fff;border-right:1px solid #ececec;text-align:center;box-sizing:border-box}ul.woocommerce_stats li:first-child{border-left:0}ul.woocommerce_stats li:last-child{border-right:0}ul.woocommerce_stats strong{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;font-size:4em;line-height:1.2em;font-weight:400;text-align:center;display:block}#woocommerce_dashboard_status .inside{padding:0;margin:0}#woocommerce_dashboard_status .wc_status_list{overflow:hidden;margin:0}#woocommerce_dashboard_status .wc_status_list li{width:50%;float:left;padding:0;box-sizing:border-box;margin:0;border-top:1px solid #ececec;color:#aaa}#woocommerce_dashboard_status .wc_status_list li a{display:block;color:#aaa;padding:9px 12px;-webkit-transition:all ease .5s;position:relative;font-size:12px}#woocommerce_dashboard_status .wc_status_list li a .wc_sparkline{width:4em;height:2em;display:block;float:right;position:absolute;right:0;top:50%;margin-right:12px;margin-top:-1.25em}#woocommerce_dashboard_status .wc_status_list li a strong{font-size:18px;line-height:1.2em;font-weight:400;display:block;color:#21759b}#woocommerce_dashboard_status .wc_status_list li a:hover{color:#2ea2cc}#woocommerce_dashboard_status .wc_status_list li a:hover strong,#woocommerce_dashboard_status .wc_status_list li a:hover:before{color:#2ea2cc!important}#woocommerce_dashboard_status .wc_status_list li a:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;margin:0 12px 12px 0;text-indent:0;top:0;left:0;height:100%;text-align:center;content:"";font-size:2em;position:relative;width:auto;line-height:1.2em;color:#464646;float:left}#woocommerce_dashboard_status .wc_status_list li:first-child{border-top:0}#woocommerce_dashboard_status .wc_status_list li.sales-this-month{width:100%}#woocommerce_dashboard_status .wc_status_list li.sales-this-month a:before{content:"\e01f"}#woocommerce_dashboard_status .wc_status_list li.best-seller-this-month{width:100%}#woocommerce_dashboard_status .wc_status_list li.best-seller-this-month a:before{content:"\e006"}#woocommerce_dashboard_status .wc_status_list li.processing-orders{border-right:1px solid #ececec}#woocommerce_dashboard_status .wc_status_list li.processing-orders a:before{content:"\e011";color:#7ad03a}#woocommerce_dashboard_status .wc_status_list li.on-hold-orders a:before{content:"\e033";color:#999}#woocommerce_dashboard_status .wc_status_list li.low-in-stock{border-right:1px solid #ececec}#woocommerce_dashboard_status .wc_status_list li.low-in-stock a:before{content:"\e02c";color:#ffba00}#woocommerce_dashboard_status .wc_status_list li.out-of-stock a:before{content:"\e02c";color:#a00}#woocommerce_dashboard_recent_reviews li{line-height:1.5em;margin-bottom:12px}#woocommerce_dashboard_recent_reviews h4.meta{line-height:1.4;margin:-.2em 0 0;font-weight:400;color:#999}#woocommerce_dashboard_recent_reviews blockquote{padding:0;margin:0}#woocommerce_dashboard_recent_reviews .avatar{float:left;margin:0 10px 5px 0}#woocommerce_dashboard_recent_reviews .star-rating{float:right;overflow:hidden;position:relative;height:1.5em;line-height:1.5;margin-left:.5em;width:5.4em;font-family:WooCommerce!important}#woocommerce_dashboard_recent_reviews .star-rating:before{content:"\e021\e021\e021\e021\e021";color:#b3b3b3;float:left;top:0;left:0;position:absolute;letter-spacing:.1em}#woocommerce_dashboard_recent_reviews .star-rating span{overflow:hidden;float:left;top:0;left:0;position:absolute;padding-top:1.5em}#woocommerce_dashboard_recent_reviews .star-rating span:before{content:"\e020\e020\e020\e020\e020";top:0;position:absolute;left:0;letter-spacing:.1em;color:#9c5d90}#dash-right-now li.product-count a:before{font-family:WooCommerce;content:"\e01d"}
@charset "UTF-8";@font-face{font-family:star;src:url(../fonts/star.eot);src:url(../fonts/star.eot?#iefix) format("embedded-opentype"),url(../fonts/star.woff) format("woff"),url(../fonts/star.ttf) format("truetype"),url(../fonts/star.svg#star) format("svg");font-weight:400;font-style:normal}@font-face{font-family:WooCommerce;src:url(../fonts/WooCommerce.eot);src:url(../fonts/WooCommerce.eot?#iefix) format("embedded-opentype"),url(../fonts/WooCommerce.woff) format("woff"),url(../fonts/WooCommerce.ttf) format("truetype"),url(../fonts/WooCommerce.svg#WooCommerce) format("svg");font-weight:400;font-style:normal}ul.woocommerce_stats{overflow:hidden;zoom:1}ul.woocommerce_stats li{width:25%;padding:0 1em;float:left;font-size:.8em;border-left:1px solid #fff;border-right:1px solid #ececec;text-align:center;box-sizing:border-box}ul.woocommerce_stats li:first-child{border-left:0}ul.woocommerce_stats li:last-child{border-right:0}#woocommerce_dashboard_status .wc_status_list li.low-in-stock,#woocommerce_dashboard_status .wc_status_list li.processing-orders{border-right:1px solid #ececec}ul.woocommerce_stats strong{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;font-size:4em;line-height:1.2em;font-weight:400;text-align:center;display:block}#woocommerce_dashboard_status .inside{padding:0;margin:0}#woocommerce_dashboard_status .wc_status_list{overflow:hidden;margin:0}#woocommerce_dashboard_status .wc_status_list li{width:50%;float:left;padding:0;box-sizing:border-box;margin:0;border-top:1px solid #ececec;color:#aaa}#woocommerce_dashboard_status .wc_status_list li a{display:block;color:#aaa;padding:9px 12px;-webkit-transition:all ease .5s;position:relative;font-size:12px}#woocommerce_dashboard_status .wc_status_list li a .wc_sparkline{width:4em;height:2em;display:block;float:right;position:absolute;right:0;top:50%;margin-right:12px;margin-top:-1.25em}#woocommerce_dashboard_status .wc_status_list li a strong{font-size:18px;line-height:1.2em;font-weight:400;display:block;color:#21759b}#woocommerce_dashboard_status .wc_status_list li a:hover{color:#2ea2cc}#woocommerce_dashboard_status .wc_status_list li a:hover strong,#woocommerce_dashboard_status .wc_status_list li a:hover:before{color:#2ea2cc!important}#woocommerce_dashboard_status .wc_status_list li a:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;margin:0 12px 12px 0;text-indent:0;top:0;left:0;height:100%;text-align:center;content:"";font-size:2em;position:relative;width:auto;line-height:1.2em;color:#464646;float:left}#woocommerce_dashboard_status .wc_status_list li.best-seller-this-month,#woocommerce_dashboard_status .wc_status_list li.sales-this-month{width:100%}#woocommerce_dashboard_status .wc_status_list li:first-child{border-top:0}#woocommerce_dashboard_status .wc_status_list li.sales-this-month a:before{content:"\e01f"}#woocommerce_dashboard_status .wc_status_list li.best-seller-this-month a:before{content:"\e006"}#woocommerce_dashboard_status .wc_status_list li.processing-orders a:before{content:"\e011";color:#7ad03a}#woocommerce_dashboard_status .wc_status_list li.on-hold-orders a:before{content:"\e033";color:#999}#woocommerce_dashboard_status .wc_status_list li.low-in-stock a:before{content:"\e02c";color:#ffba00}#woocommerce_dashboard_status .wc_status_list li.out-of-stock a:before{content:"\e02c";color:#a00}#woocommerce_dashboard_recent_reviews li{line-height:1.5em;margin-bottom:12px}#woocommerce_dashboard_recent_reviews h4.meta{line-height:1.4;margin:-.2em 0 0;font-weight:400;color:#999}#woocommerce_dashboard_recent_reviews blockquote{padding:0;margin:0}#woocommerce_dashboard_recent_reviews .avatar{float:left;margin:0 10px 5px 0}#woocommerce_dashboard_recent_reviews .star-rating{float:right;overflow:hidden;position:relative;height:1.5em;line-height:1.5;margin-left:.5em;width:5.4em;font-family:WooCommerce!important}#woocommerce_dashboard_recent_reviews .star-rating:before{content:"\e021\e021\e021\e021\e021";color:#b3b3b3;float:left;top:0;left:0;position:absolute;letter-spacing:.1em}#woocommerce_dashboard_recent_reviews .star-rating span{overflow:hidden;float:left;top:0;left:0;position:absolute;padding-top:1.5em}#woocommerce_dashboard_recent_reviews .star-rating span:before{content:"\e020\e020\e020\e020\e020";top:0;position:absolute;left:0;letter-spacing:.1em;color:#9c5d90}#dash-right-now li.product-count a:before{font-family:WooCommerce;content:"\e01d"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

102
assets/js/admin/api-keys.js Normal file
View File

@ -0,0 +1,102 @@
/*global jQuery, Backbone, _, woocommerce_admin_api_keys */
(function( $ ) {
var APIView = Backbone.View.extend({
el: $( '#key-fields' ),
events: {
'click input#update_api_key': 'saveKey'
},
initialize: function(){
_.bindAll( this, 'saveKey' );
},
block: function() {
$( this.el ).block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
},
unblock: function() {
$( this.el ).unblock();
},
initTipTip: function() {
$( '.copy-key', this.el ).tipTip({
'attribute': 'data-tip',
'activation': 'click',
'fadeIn': 50,
'fadeOut': 50,
'delay': 0
});
$( document.body ).on( 'copy', '.copy-key', function( e ) {
e.clipboardData.clearData();
e.clipboardData.setData( 'text/plain', $.trim( $( this ).prev( 'code' ).html() ) );
e.preventDefault();
});
},
createQRCode: function( consumer_key, consumer_secret ) {
$( '#keys-qrcode' ).qrcode({
text: consumer_key + '|' + consumer_secret,
width: 120,
height: 120
});
},
saveKey: function( e ) {
e.preventDefault();
var self = this;
self.block();
Backbone.ajax({
method: 'POST',
dataType: 'json',
url: woocommerce_admin_api_keys.ajax_url,
data: {
action: 'woocommerce_update_api_key',
security: woocommerce_admin_api_keys.update_api_nonce,
key_id: $( '#key_id', self.el ).val(),
description: $( '#key_description', self.el ).val(),
user: $( '#key_user', self.el ).val(),
permissions: $( '#key_permissions', self.el ).val()
},
success: function( response ) {
$( '.wc-api-message', self.el ).remove();
if ( response.success ) {
var data = response.data;
$( 'h3', self.el ).first().append( '<div class="wc-api-message updated"><p>' + data.message + '</p></div>' );
if ( 0 < data.consumer_key.length && 0 < data.consumer_secret.length ) {
$( '#api-keys-options', self.el ).remove();
$( 'p.submit', self.el ).empty().append( data.revoke_url );
var keysTemplate = _.template( $( '#api-keys-template' ).html(), {
consumer_key: data.consumer_key,
consumer_secret: data.consumer_secret
});
$( 'p.submit', self.el ).before( keysTemplate );
self.createQRCode( data.consumer_key, data.consumer_secret );
self.initTipTip();
} else {
$( '#key_description', self.el ).val( data.description );
$( '#key_user', self.el ).val( data.user_id );
$( '#key_permissions', self.el ).val( data.permissions );
}
} else {
$( 'h3', self.el ).first().append( '<div class="wc-api-message error"><p>' + response.data.message + '</p></div>' );
}
self.unblock();
}
});
}
});
new APIView();
})( jQuery );

1
assets/js/admin/api-keys.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(a){var b=Backbone.View.extend({el:a("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},initTipTip:function(){a(".copy-key",this.el).tipTip({attribute:"data-tip",activation:"click",fadeIn:50,fadeOut:50,delay:0}),a(document.body).on("copy",".copy-key",function(b){b.clipboardData.clearData(),b.clipboardData.setData("text/plain",a.trim(a(this).prev("code").html())),b.preventDefault()})},createQRCode:function(b,c){a("#keys-qrcode").qrcode({text:b+"|"+c,width:120,height:120})},saveKey:function(b){b.preventDefault();var c=this;c.block(),Backbone.ajax({method:"POST",dataType:"json",url:woocommerce_admin_api_keys.ajax_url,data:{action:"woocommerce_update_api_key",security:woocommerce_admin_api_keys.update_api_nonce,key_id:a("#key_id",c.el).val(),description:a("#key_description",c.el).val(),user:a("#key_user",c.el).val(),permissions:a("#key_permissions",c.el).val()},success:function(b){if(a(".wc-api-message",c.el).remove(),b.success){var d=b.data;if(a("h3",c.el).first().append('<div class="wc-api-message updated"><p>'+d.message+"</p></div>"),0<d.consumer_key.length&&0<d.consumer_secret.length){a("#api-keys-options",c.el).remove(),a("p.submit",c.el).empty().append(d.revoke_url);var e=_.template(a("#api-keys-template").html(),{consumer_key:d.consumer_key,consumer_secret:d.consumer_secret});a("p.submit",c.el).before(e),c.createQRCode(d.consumer_key,d.consumer_secret),c.initTipTip()}else a("#key_description",c.el).val(d.description),a("#key_user",c.el).val(d.user_id),a("#key_permissions",c.el).val(d.permissions)}else a("h3",c.el).first().append('<div class="wc-api-message error"><p>'+b.data.message+"</p></div>");c.unblock()}})}});new b}(jQuery);

File diff suppressed because one or more lines are too long

View File

@ -1,28 +0,0 @@
(function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;d<a.length&&0==a[d];)d++;this.num=Array(a.length-d+c);for(var b=0;b<a.length-d;b++)this.num[b]=a[b+d]}function p(a,c){this.totalCount=a;this.dataCount=c}function t(){this.buffer=[];this.length=0}u.prototype={getLength:function(){return this.data.length},
write:function(a){for(var c=0;c<this.data.length;c++)a.put(this.data.charCodeAt(c),8)}};o.prototype={addData:function(a){this.dataList.push(new u(a));this.dataCache=null},isDark:function(a,c){if(0>a||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e<c.length;e++)b+=c[e].dataCount;
for(e=0;e<this.dataList.length;e++)c=this.dataList[e],d.put(c.mode,4),d.put(c.getLength(),j.getLengthInBits(c.mode,a)),c.write(d);if(d.getLengthInBits()<=8*b)break}this.typeNumber=a}this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17;this.modules=Array(this.moduleCount);for(var d=0;d<this.moduleCount;d++){this.modules[d]=Array(this.moduleCount);for(var b=0;b<this.moduleCount;b++)this.modules[d][b]=null}this.setupPositionProbePattern(0,0);this.setupPositionProbePattern(this.moduleCount-
7,0);this.setupPositionProbePattern(0,this.moduleCount-7);this.setupPositionAdjustPattern();this.setupTimingPattern();this.setupTypeInfo(a,c);7<=this.typeNumber&&this.setupTypeNumber(a);null==this.dataCache&&(this.dataCache=o.createData(this.typeNumber,this.errorCorrectLevel,this.dataList));this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,c){for(var d=-1;7>=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]=
0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c<this.modules.length;c++)for(var d=1*c,b=0;b<this.modules[c].length;b++){var e=1*b;this.modules[c][b]&&(a.beginFill(0,100),a.moveTo(e,d),a.lineTo(e+1,d),a.lineTo(e+1,d+1),a.lineTo(e,d+1),a.endFill())}return a},
setupTimingPattern:function(){for(var a=8;a<this.moduleCount-8;a++)null==this.modules[a][6]&&(this.modules[a][6]=0==a%2);for(a=8;a<this.moduleCount-8;a++)null==this.modules[6][a]&&(this.modules[6][a]=0==a%2)},setupPositionAdjustPattern:function(){for(var a=j.getPatternPosition(this.typeNumber),c=0;c<a.length;c++)for(var d=0;d<a.length;d++){var b=a[c],e=a[d];if(null==this.modules[b][e])for(var f=-2;2>=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c=
j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&1),this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount-
b-1]=e:9>b?this.modules[8][15-b-1+1]=e:this.modules[8][15-b-1]=e;this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,i=this.moduleCount-1;0<i;i-=2)for(6==i&&i--;;){for(var g=0;2>g;g++)if(null==this.modules[b][i-g]){var n=!1;f<a.length&&(n=1==(a[f]>>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a,
c),b=new t,e=0;e<d.length;e++){var f=d[e];b.put(f.mode,4);b.put(f.getLength(),j.getLengthInBits(f.mode,a));f.write(b)}for(e=a=0;e<c.length;e++)a+=c[e].dataCount;if(b.getLengthInBits()>8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d=
0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g<c.length;g++){var n=c[g].dataCount,h=c[g].totalCount-n,b=Math.max(b,n),e=Math.max(e,h);f[g]=Array(n);for(var k=0;k<f[g].length;k++)f[g][k]=255&a.buffer[k+d];d+=n;k=j.getErrorCorrectPolynomial(h);n=(new q(f[g],k.getLength()-1)).mod(k);i[g]=Array(k.getLength()-1);for(k=0;k<i[g].length;k++)h=k+n.getLength()-i[g].length,i[g][k]=0<=h?n.get(h):0}for(k=g=0;k<c.length;k++)g+=c[k].totalCount;d=Array(g);for(k=n=0;k<b;k++)for(g=0;g<c.length;g++)k<f[g].length&&
(d[n++]=f[g][k]);for(k=0;k<e;k++)for(g=0;g<c.length;g++)k<i[g].length&&(d[n++]=i[g][k]);return d};s=4;for(var j={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,
78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(a){for(var c=a<<10;0<=j.getBCHDigit(c)-j.getBCHDigit(j.G15);)c^=j.G15<<j.getBCHDigit(c)-j.getBCHDigit(j.G15);return(a<<10|c)^j.G15_MASK},getBCHTypeNumber:function(a){for(var c=a<<12;0<=j.getBCHDigit(c)-
j.getBCHDigit(j.G18);)c^=j.G18<<j.getBCHDigit(c)-j.getBCHDigit(j.G18);return a<<12|c},getBCHDigit:function(a){for(var c=0;0!=a;)c++,a>>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+
a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;d<a;d++)c=c.multiply(new q([1,l.gexp(d)],0));return c},getLengthInBits:function(a,c){if(1<=c&&10>c)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+
a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b<c;b++)for(var e=0;e<c;e++){for(var f=0,i=a.isDark(b,e),g=-1;1>=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5<f&&(d+=3+f-5)}for(b=0;b<c-1;b++)for(e=0;e<c-1;e++)if(f=0,a.isDark(b,e)&&f++,a.isDark(b+1,e)&&f++,a.isDark(b,e+1)&&f++,a.isDark(b+1,e+1)&&f++,0==f||4==f)d+=3;for(b=0;b<c;b++)for(e=0;e<c-6;e++)a.isDark(b,e)&&!a.isDark(b,e+1)&&a.isDark(b,e+
2)&&a.isDark(b,e+3)&&a.isDark(b,e+4)&&!a.isDark(b,e+5)&&a.isDark(b,e+6)&&(d+=40);for(e=0;e<c;e++)for(b=0;b<c-6;b++)a.isDark(b,e)&&!a.isDark(b+1,e)&&a.isDark(b+2,e)&&a.isDark(b+3,e)&&a.isDark(b+4,e)&&!a.isDark(b+5,e)&&a.isDark(b+6,e)&&(d+=40);for(e=f=0;e<c;e++)for(b=0;b<c;b++)a.isDark(b,e)&&f++;a=Math.abs(100*f/c/c-50)/5;return d+10*a}},l={glog:function(a){if(1>a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256),
LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<<m;for(m=8;256>m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d<this.getLength();d++)for(var b=0;b<a.getLength();b++)c[d+b]^=l.gexp(l.glog(this.get(d))+l.glog(a.get(b)));return new q(c,0)},mod:function(a){if(0>
this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b<this.getLength();b++)d[b]=this.get(b);for(b=0;b<a.getLength();b++)d[b]^=l.gexp(l.glog(a.get(b))+c);return(new q(d,0)).mod(a)}};p.RS_BLOCK_TABLE=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],
[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,
116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,
43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,
3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,
55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,
45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]];p.getRSBlocks=function(a,c){var d=p.getRsBlockTable(a,c);if(void 0==d)throw Error("bad rs block @ typeNumber:"+a+"/errorCorrectLevel:"+c);for(var b=d.length/3,e=[],f=0;f<b;f++)for(var h=d[3*f+0],g=d[3*f+1],j=d[3*f+2],l=0;l<h;l++)e.push(new p(g,j));return e};p.getRsBlockTable=function(a,c){switch(c){case 1:return p.RS_BLOCK_TABLE[4*(a-1)+0];case 0:return p.RS_BLOCK_TABLE[4*(a-1)+1];case 3:return p.RS_BLOCK_TABLE[4*
(a-1)+2];case 2:return p.RS_BLOCK_TABLE[4*(a-1)+3]}};t.prototype={get:function(a){return 1==(this.buffer[Math.floor(a/8)]>>>7-a%8&1)},put:function(a,c){for(var d=0;d<c;d++)this.putBit(1==(a>>>c-d-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1,
correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f<a.getModuleCount();f++)for(var i=0;i<a.getModuleCount();i++){d.fillStyle=a.isDark(f,i)?h.foreground:h.background;var g=Math.ceil((i+1)*b)-Math.floor(i*b),
j=Math.ceil((f+1)*b)-Math.floor(f*b);d.fillRect(Math.round(i*b),Math.round(f*e),g,j)}}else{a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();c=r("<table></table>").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e<a.getModuleCount();e++){f=r("<tr></tr>").css("height",b+"px").appendTo(c);for(i=0;i<a.getModuleCount();i++)r("<td></td>").css("width",
d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;jQuery(a).appendTo(this)})}})(jQuery);

View File

@ -3,67 +3,69 @@
*
* Modified - products have no children (non hierarchical)
*/
( function( $ ){
$( document ).ready(function(){
$('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
( function( $ ) {
$( document ).ready( function() {
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
$("table.widefat tbody").sortable({
$( 'table.widefat tbody' ).sortable({
items: 'tr:not(.inline-edit-row)',
cursor: 'move',
axis: 'y',
containment: 'table.widefat',
scrollSensitivity: 40,
helper: function(event, ui) {
ui.each(function() { $(this).width($(this).width()); });
helper: function( event, ui ) {
ui.each( function() {
$( this ).width( $( this ).width() );
});
return ui;
},
start: function(event, ui) {
ui.placeholder.children().each(function(){
var $original = ui.item.children().eq( ui.placeholder.children().index(this) ),
start: function( event, ui ) {
ui.placeholder.children().each( function() {
var $original = ui.item.children().eq( ui.placeholder.children().index( this ) ),
$this = $( this );
$.each( $original[0].attributes, function( k, attr ){
$.each( $original[0].attributes, function( k, attr ) {
$this.attr( attr.name, attr.value );
} );
});
});
if ( ! ui.item.hasClass('alternate') ) {
if ( ! ui.item.hasClass( 'alternate' ) ) {
ui.item.css( 'background-color', '#ffffff' );
}
ui.item.children('td,th').css('border-bottom-width','0');
ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
ui.item.css( 'outline', '1px solid #dfdfdf' );
},
stop: function(event, ui) {
ui.item.removeAttr('style');
ui.item.children('td,th').css('border-bottom-width','1px');
stop: function( event, ui ) {
ui.item.removeAttr( 'style' );
ui.item.children( 'td,th' ).css( 'border-bottom-width', '1px' );
},
update: function(event, ui) {
$('table.widefat tbody th, table.widefat tbody td').css('cursor','default');
$("table.widefat tbody").sortable('disable');
update: function( event, ui ) {
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'default' );
$( 'table.widefat tbody' ).sortable( 'disable' );
var postid = ui.item.find('.check-column input').val(); // this post id
var postparent = ui.item.find('.post_parent').html(); // post parent
var postid = ui.item.find( '.check-column input' ).val();
var prevpostid = ui.item.prev().find( '.check-column input' ).val();
var nextpostid = ui.item.next().find( '.check-column input' ).val();
var prevpostid = ui.item.prev().find('.check-column input').val();
var nextpostid = ui.item.next().find('.check-column input').val();
// Show Spinner
ui.item.find( '.check-column input' ).hide().after( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' );
// show spinner
ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');
// go do the sorting stuff via ajax
$.post( ajaxurl, { action: 'woocommerce_product_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function(response){
$.each(response, function(key,value) { $('#inline_'+key+' .menu_order').html(value); });
ui.item.find('.check-column input').show().siblings('img').remove();
$('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
$("table.widefat tbody").sortable('enable');
// Go do the sorting stuff via ajax
$.post( ajaxurl, { action: 'woocommerce_product_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function( response ) {
$.each( response, function( key, value ) {
$( '#inline_' + key + ' .menu_order' ).html( value );
});
ui.item.find( '.check-column input' ).show().siblings( 'img' ).remove();
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
$( 'table.widefat tbody' ).sortable( 'enable' );
});
// fix cell colors
$( 'table.widefat tbody tr' ).each(function(){
var i = $('table.widefat tbody tr').index(this);
if ( i%2 === 0 ){
$(this).addClass('alternate');
$( 'table.widefat tbody tr' ).each( function() {
var i = $( 'table.widefat tbody tr' ).index( this );
if ( i%2 === 0 ) {
$( this ).addClass( 'alternate' );
} else {
$(this).removeClass('alternate');
$( this ).removeClass( 'alternate' );
}
});
}

View File

@ -1 +1 @@
!function(a){a(document).ready(function(){a("table.widefat tbody th, table.widefat tbody td").css("cursor","move"),a("table.widefat tbody").sortable({items:"tr:not(.inline-edit-row)",cursor:"move",axis:"y",containment:"table.widefat",scrollSensitivity:40,helper:function(b,c){return c.each(function(){a(this).width(a(this).width())}),c},start:function(b,c){c.placeholder.children().each(function(){var b=c.item.children().eq(c.placeholder.children().index(this)),d=a(this);a.each(b[0].attributes,function(a,b){d.attr(b.name,b.value)})}),c.item.hasClass("alternate")||c.item.css("background-color","#ffffff"),c.item.children("td,th").css("border-bottom-width","0"),c.item.css("outline","1px solid #dfdfdf")},stop:function(a,b){b.item.removeAttr("style"),b.item.children("td,th").css("border-bottom-width","1px")},update:function(b,c){a("table.widefat tbody th, table.widefat tbody td").css("cursor","default"),a("table.widefat tbody").sortable("disable");var d=c.item.find(".check-column input").val(),e=(c.item.find(".post_parent").html(),c.item.prev().find(".check-column input").val()),f=c.item.next().find(".check-column input").val();c.item.find(".check-column input").hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),a.post(ajaxurl,{action:"woocommerce_product_ordering",id:d,previd:e,nextid:f},function(b){a.each(b,function(b,c){a("#inline_"+b+" .menu_order").html(c)}),c.item.find(".check-column input").show().siblings("img").remove(),a("table.widefat tbody th, table.widefat tbody td").css("cursor","move"),a("table.widefat tbody").sortable("enable")}),a("table.widefat tbody tr").each(function(){var b=a("table.widefat tbody tr").index(this);b%2===0?a(this).addClass("alternate"):a(this).removeClass("alternate")})}})})}(jQuery);
!function(a){a(document).ready(function(){a("table.widefat tbody th, table.widefat tbody td").css("cursor","move"),a("table.widefat tbody").sortable({items:"tr:not(.inline-edit-row)",cursor:"move",axis:"y",containment:"table.widefat",scrollSensitivity:40,helper:function(b,c){return c.each(function(){a(this).width(a(this).width())}),c},start:function(b,c){c.placeholder.children().each(function(){var b=c.item.children().eq(c.placeholder.children().index(this)),d=a(this);a.each(b[0].attributes,function(a,b){d.attr(b.name,b.value)})}),c.item.hasClass("alternate")||c.item.css("background-color","#ffffff"),c.item.children("td, th").css("border-bottom-width","0"),c.item.css("outline","1px solid #dfdfdf")},stop:function(a,b){b.item.removeAttr("style"),b.item.children("td,th").css("border-bottom-width","1px")},update:function(b,c){a("table.widefat tbody th, table.widefat tbody td").css("cursor","default"),a("table.widefat tbody").sortable("disable");var d=c.item.find(".check-column input").val(),e=c.item.prev().find(".check-column input").val(),f=c.item.next().find(".check-column input").val();c.item.find(".check-column input").hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),a.post(ajaxurl,{action:"woocommerce_product_ordering",id:d,previd:e,nextid:f},function(b){a.each(b,function(b,c){a("#inline_"+b+" .menu_order").html(c)}),c.item.find(".check-column input").show().siblings("img").remove(),a("table.widefat tbody th, table.widefat tbody td").css("cursor","move"),a("table.widefat tbody").sortable("enable")}),a("table.widefat tbody tr").each(function(){var b=a("table.widefat tbody tr").index(this);b%2===0?a(this).addClass("alternate"):a(this).removeClass("alternate")})}})})}(jQuery);

View File

@ -1,9 +1,9 @@
/* Modifided script from the simple-page-ordering plugin */
jQuery(function($) {
jQuery( function( $ ) {
$('table.widefat.wp-list-table tbody th, table.widefat tbody td').css('cursor','move');
$( 'table.widefat.wp-list-table tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
$("table.widefat.wp-list-table").sortable({
$( 'table.widefat.wp-list-table' ).sortable({
items: 'tbody tr:not(.inline-edit-row)',
cursor: 'move',
axis: 'y',
@ -12,57 +12,66 @@ jQuery(function($) {
opacity: 0.65,
placeholder: 'product-cat-placeholder',
scrollSensitivity: 40,
start: function(event, ui) {
if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' );
ui.item.children('td,th').css('border-bottom-width','0');
start: function( event, ui ) {
if ( ! ui.item.hasClass( 'alternate' ) ) {
ui.item.css( 'background-color', '#ffffff' );
}
ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
ui.item.css( 'outline', '1px solid #aaa' );
},
stop: function(event, ui) {
ui.item.removeAttr('style');
ui.item.children('td,th').css('border-bottom-width','1px');
stop: function( event, ui ) {
ui.item.removeAttr( 'style' );
ui.item.children( 'td, th' ).css( 'border-bottom-width', '1px' );
},
update: function(event, ui) {
var termid = ui.item.find('.check-column input').val(); // this post id
var termparent = ui.item.find('.parent').html(); // post parent
update: function( event, ui ) {
var termid = ui.item.find( '.check-column input' ).val(); // this post id
var termparent = ui.item.find( '.parent' ).html(); // post parent
var prevtermid = ui.item.prev().find('.check-column input').val();
var nexttermid = ui.item.next().find('.check-column input').val();
var prevtermid = ui.item.prev().find( '.check-column input' ).val();
var nexttermid = ui.item.next().find( '.check-column input' ).val();
// can only sort in same tree
var prevtermparent = undefined;
if ( prevtermid != undefined ) {
var prevtermparent = ui.item.prev().find('.parent').html();
if ( prevtermparent != termparent) prevtermid = undefined;
// Can only sort in same tree
var prevtermparent, nexttermparent;
if ( prevtermid !== undefined ) {
prevtermparent = ui.item.prev().find( '.parent' ).html();
if ( prevtermparent !== termparent) {
prevtermid = undefined;
}
}
var nexttermparent = undefined;
if ( nexttermid != undefined ) {
nexttermparent = ui.item.next().find('.parent').html();
if ( nexttermparent != termparent) nexttermid = undefined;
if ( nexttermid !== undefined ) {
nexttermparent = ui.item.next().find( '.parent' ).html();
if ( nexttermparent !== termparent) {
nexttermid = undefined;
}
}
// if previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children
if ( ( prevtermid == undefined && nexttermid == undefined ) || ( nexttermid == undefined && nexttermparent == prevtermid ) || ( nexttermid != undefined && prevtermparent == termid ) ) {
$("table.widefat.wp-list-table").sortable('cancel');
// If previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children
if ( ( prevtermid === undefined && nexttermid === undefined ) || ( nexttermid === undefined && nexttermparent === prevtermid ) || ( nexttermid !== undefined && prevtermparent === termid ) ) {
$( 'table.widefat.wp-list-table' ).sortable( 'cancel' );
return;
}
// show spinner
ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');
// Show Spinner
ui.item.find( '.check-column input' ).hide().after( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' );
// go do the sorting stuff via ajax
// Go do the sorting stuff via ajax
$.post( ajaxurl, { action: 'woocommerce_term_ordering', id: termid, nextid: nexttermid, thetaxonomy: woocommerce_term_ordering_params.taxonomy }, function(response){
if ( response == 'children' ) window.location.reload();
else {
ui.item.find('.check-column input').show().siblings('img').remove();
if ( response === 'children' ) {
window.location.reload();
} else {
ui.item.find( '.check-column input' ).show().siblings( 'img' ).remove();
}
});
// fix cell colors
$( 'table.widefat tbody tr' ).each(function(){
var i = jQuery('table.widefat tbody tr').index(this);
if ( i%2 == 0 ) jQuery(this).addClass('alternate');
else jQuery(this).removeClass('alternate');
// Fix cell colors
$( 'table.widefat tbody tr' ).each( function() {
var i = jQuery( 'table.widefat tbody tr' ).index( this );
if ( i%2 === 0 ) {
jQuery( this ).addClass( 'alternate' );
} else {
jQuery( this ).removeClass( 'alternate' );
}
});
}
});

View File

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

View File

@ -1,3 +1,4 @@
/* global wc_cart_fragments_params */
jQuery( function( $ ) {
// wc_cart_fragments_params is required to continue, ensure the object exists
@ -5,7 +6,8 @@ jQuery( function( $ ) {
return false;
}
/** Cart Handling */
/* Storage Handling */
var $supports_html5_storage;
try {
$supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null );
@ -15,7 +17,7 @@ jQuery( function( $ ) {
$supports_html5_storage = false;
}
$fragment_refresh = {
var $fragment_refresh = {
url: wc_cart_fragments_params.wc_ajax_url + 'get_refreshed_fragments',
type: 'POST',
success: function( data ) {
@ -35,6 +37,7 @@ jQuery( function( $ ) {
}
};
/* Cart Handling */
if ( $supports_html5_storage ) {
$( document.body ).bind( 'added_to_cart', function( event, fragments, cart_hash ) {
@ -55,14 +58,13 @@ jQuery( function( $ ) {
cookie_hash = '';
}
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash == cookie_hash ) {
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash === cookie_hash ) {
$.each( wc_fragments, function( key, value ) {
$( key ).replaceWith(value);
});
$( document.body ).trigger( 'wc_fragments_loaded' );
} else {
throw 'No fragment';
}
@ -75,7 +77,7 @@ jQuery( function( $ ) {
$.ajax( $fragment_refresh );
}
/* Cart hiding */
/* Cart Hiding */
if ( $.cookie( 'woocommerce_items_in_cart' ) > 0 ) {
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
} else {
@ -84,6 +86,5 @@ jQuery( function( $ ) {
$( document.body ).bind( 'adding_to_cart', function() {
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
} );
});
});

View File

@ -1 +1 @@
jQuery(function(a){if("undefined"==typeof wc_cart_fragments_params)return!1;try{$supports_html5_storage="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc")}catch(b){$supports_html5_storage=!1}if($fragment_refresh={url:wc_cart_fragments_params.wc_ajax_url+"get_refreshed_fragments",type:"POST",success:function(b){b&&b.fragments&&(a.each(b.fragments,function(b,c){a(b).replaceWith(c)}),$supports_html5_storage&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(b.fragments)),sessionStorage.setItem("wc_cart_hash",b.cart_hash)),a(document.body).trigger("wc_fragments_refreshed"))}},$supports_html5_storage){a(document.body).bind("added_to_cart",function(a,b,c){sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(b)),sessionStorage.setItem("wc_cart_hash",c)});try{var c=a.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),d=sessionStorage.getItem("wc_cart_hash"),e=a.cookie("woocommerce_cart_hash");if((null===d||void 0===d||""===d)&&(d=""),(null===e||void 0===e||""===e)&&(e=""),!c||!c["div.widget_shopping_cart_content"]||d!=e)throw"No fragment";a.each(c,function(b,c){a(b).replaceWith(c)}),a(document.body).trigger("wc_fragments_loaded")}catch(b){a.ajax($fragment_refresh)}}else a.ajax($fragment_refresh);a.cookie("woocommerce_items_in_cart")>0?a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),a(document.body).bind("adding_to_cart",function(){a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()})});
jQuery(function(a){if("undefined"==typeof wc_cart_fragments_params)return!1;var b;try{b="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc")}catch(c){b=!1}var d={url:wc_cart_fragments_params.wc_ajax_url+"get_refreshed_fragments",type:"POST",success:function(c){c&&c.fragments&&(a.each(c.fragments,function(b,c){a(b).replaceWith(c)}),b&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(c.fragments)),sessionStorage.setItem("wc_cart_hash",c.cart_hash)),a(document.body).trigger("wc_fragments_refreshed"))}};if(b){a(document.body).bind("added_to_cart",function(a,b,c){sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(b)),sessionStorage.setItem("wc_cart_hash",c)});try{var e=a.parseJSON(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),f=sessionStorage.getItem("wc_cart_hash"),g=a.cookie("woocommerce_cart_hash");if((null===f||void 0===f||""===f)&&(f=""),(null===g||void 0===g||""===g)&&(g=""),!e||!e["div.widget_shopping_cart_content"]||f!==g)throw"No fragment";a.each(e,function(b,c){a(b).replaceWith(c)}),a(document.body).trigger("wc_fragments_loaded")}catch(c){a.ajax(d)}}else a.ajax(d);a.cookie("woocommerce_items_in_cart")>0?a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),a(document.body).bind("adding_to_cart",function(){a(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()})});

View File

@ -1,3 +1,4 @@
/* global wc_cart_params */
jQuery( function( $ ) {
// wc_cart_params is required to continue, ensure the object exists
@ -8,15 +9,13 @@ jQuery( function( $ ) {
// Shipping calculator
$( document ).on( 'click', '.shipping-calculator-button', function() {
$( '.shipping-calculator-form' ).slideToggle( 'slow' );
return false;
}).on( 'change', 'select.shipping_method, input[name^=shipping_method]', function() {
var shipping_methods = [];
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function( index, input ) {
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function() {
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
} );
});
$( 'div.cart_totals' ).block({
message: null,
@ -32,13 +31,10 @@ jQuery( function( $ ) {
};
$.post( wc_cart_params.wc_ajax_url + 'update_shipping_method', data, function( response ) {
$( 'div.cart_totals' ).replaceWith( response );
$( document.body ).trigger( 'updated_shipping_method' );
});
});
$( '.shipping-calculator-form' ).hide();
});

View File

@ -62,11 +62,11 @@ jQuery( function( $ ) {
},
maybe_input_changed: function( e ) {
if ( wc_checkout_form.dirtyInput ) {
wc_checkout_form.input_changed();
wc_checkout_form.input_changed( e );
}
},
input_changed: function( e ) {
wc_checkout_form.dirtyInput = this;
wc_checkout_form.dirtyInput = e.target;
wc_checkout_form.maybe_update_checkout();
},
queue_update_checkout: function( e ) {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

0
assets/js/prettyPhoto/jquery.prettyPhoto.js Executable file → Normal file
View File

0
assets/js/select2/select2.js vendored Executable file → Normal file
View File

4
assets/js/select2/select2.min.js vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,7 @@ $states['CA'] = array(
'BC' => __( 'British Columbia', 'woocommerce' ),
'MB' => __( 'Manitoba', 'woocommerce' ),
'NB' => __( 'New Brunswick', 'woocommerce' ),
'NL' => __( 'Newfoundland', 'woocommerce' ),
'NL' => __( 'Newfoundland and Labrador', 'woocommerce' ),
'NT' => __( 'Northwest Territories', 'woocommerce' ),
'NS' => __( 'Nova Scotia', 'woocommerce' ),
'NU' => __( 'Nunavut', 'woocommerce' ),

View File

@ -293,6 +293,15 @@ class WC_Product {
}
}
/**
* Return the product type.
*
* @return string
*/
public function get_type() {
return is_null( $this->product_type ) ? '' : $this->product_type;
}
/**
* Checks the product type.
*

View File

@ -176,6 +176,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
FROM {$wpdb->prefix}woocommerce_api_keys
WHERE 1 = 1
$search
ORDER BY key_id DESC
LIMIT %d
OFFSET %d
", $per_page, $offset ), ARRAY_A );
@ -188,7 +189,7 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
$this->set_pagination_args( array(
'total_items' => $count,
'per_page' => $per_page,
'total_pages' => $count / $per_page
'total_pages' => ceil( $count / $per_page )
) );
}
}

View File

@ -113,11 +113,6 @@ class WC_Admin_API_Keys {
*/
public function actions() {
if ( $this->is_api_keys_settings_page() ) {
// Generate Key / Edit Key
if ( isset( $_POST['update_api_key'] ) && isset( $_POST['key_id'] ) ) {
$this->update_key();
}
// Revoke key
if ( isset( $_GET['revoke-key'] ) ) {
$this->revoke_key();
@ -134,113 +129,8 @@ class WC_Admin_API_Keys {
* Notices.
*/
public static function notices() {
if ( isset( $_GET['status'] ) ) {
switch ( intval( $_GET['status'] ) ) {
case 2 :
WC_Admin_Settings::add_message( __( 'API Key generated successfully.', 'woocommerce' ) );
break;
case 3 :
WC_Admin_Settings::add_message( __( 'API Key revoked successfully.', 'woocommerce' ) );
break;
case -1 :
WC_Admin_Settings::add_error( __( 'Description is missing.', 'woocommerce' ) );
break;
case -2 :
WC_Admin_Settings::add_error( __( 'User is missing.', 'woocommerce' ) );
break;
case -3 :
WC_Admin_Settings::add_error( __( 'Description is missing.', 'woocommerce' ) );
break;
default :
WC_Admin_Settings::add_message( __( 'API Key updated successfully.', 'woocommerce' ) );
break;
}
}
}
/**
* Update Key
*/
private function update_key() {
global $wpdb;
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) ) {
wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
}
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
$url = admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' );
$key_id = absint( $_POST['key_id'] );
$status = 1;
try {
if ( empty( $_POST['key_description'] ) ) {
throw new Exception( 'Description is missing', -1 );
}
if ( empty( $_POST['key_user'] ) ) {
throw new Exception( 'User is missing', -2 );
}
if ( empty( $_POST['key_permissions'] ) ) {
throw new Exception( 'permissions is missing', -3 );
}
$description = sanitize_text_field( $_POST['key_description'] );
$permissions = ( in_array( $_POST['key_permissions'], array( 'read', 'write', 'read_write' ) ) ) ? sanitize_text_field( $_POST['key_permissions'] ) : 'read';
$user_id = absint( $_POST['key_user'] );
if ( 0 < $key_id ) {
$wpdb->update(
$wpdb->prefix . 'woocommerce_api_keys',
array(
'user_id' => $user_id,
'description' => $description,
'permissions' => $permissions
),
array( 'key_id' => $key_id ),
array(
'%d',
'%s',
'%s'
),
array( '%d' )
);
} else {
$status = 2;
$user = get_userdata( $user_id );
$consumer_key = 'ck_' . hash( 'md5', $user->user_login . date( 'U' ) . mt_rand() );
$consumer_secret = 'cs_' . hash( 'md5', $user->ID . date( 'U' ) . mt_rand() );
$wpdb->insert(
$wpdb->prefix . 'woocommerce_api_keys',
array(
'user_id' => $user_id,
'description' => $description,
'permissions' => $permissions,
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret
),
array(
'%d',
'%s',
'%s',
'%s',
'%s'
)
);
$key_id = $wpdb->insert_id;
}
wp_redirect( esc_url_raw( add_query_arg( array( 'edit-key' => $key_id, 'status' => $status ), $url ) ) );
exit();
} catch ( Exception $e ) {
wp_redirect( esc_url_raw( add_query_arg( array( 'edit-key' => $key_id, 'status' => $e->getCode() ), $url ) ) );
exit();
if ( isset( $_GET['revoked'] ) && 1 == $_GET['revoked'] ) {
WC_Admin_Settings::add_message( __( 'API Key revoked successfully.', 'woocommerce' ) );
}
}
@ -255,7 +145,7 @@ class WC_Admin_API_Keys {
$key_id = absint( $_GET['revoke-key'] );
$this->remove_key( $key_id );
wp_redirect( esc_url_raw( add_query_arg( array( 'status' => 3 ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ) ) );
wp_redirect( esc_url_raw( add_query_arg( array( 'revoked' => 1 ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ) ) );
exit();
}

View File

@ -88,7 +88,7 @@ class WC_Admin_Assets {
wp_register_script( 'round', WC()->plugin_url() . '/assets/js/admin/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable' ), WC_VERSION );
wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/admin/jquery.qrcode.min.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'wc-admin-notices', WC()->plugin_url() . '/assets/js/admin/woocommerce_notices' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
@ -292,13 +292,20 @@ class WC_Admin_Assets {
}
// API settings
if ( 'woocommerce_page_wc-settings' === $screen->id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
wp_enqueue_script( 'qrcode' );
wp_enqueue_script( 'zeroclipboard' );
if ( $wc_screen_id . '_page_wc-settings' === $screen->id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
wp_enqueue_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'qrcode', 'zeroclipboard' ), WC_VERSION, true );
wp_localize_script(
'wc-api-keys',
'woocommerce_admin_api_keys',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'update_api_nonce' => wp_create_nonce( 'update-api-key' )
)
);
}
// System status
if ( 'woocommerce_page_wc-status' === $screen->id ) {
if ( $wc_screen_id . '_page_wc-status' === $screen->id ) {
wp_enqueue_script( 'zeroclipboard' );
}

View File

@ -168,13 +168,11 @@ class WC_Admin_Duplicate_Product {
$this->duplicate_post_meta( $post->ID, $new_post_id );
// Copy the children (variations)
if ( $children_products = get_children( 'post_parent='.$post->ID.'&post_type=product_variation' ) ) {
$exclude = array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_children', false, $post ) );
if ( $children_products ) {
foreach ( $children_products as $child ) {
$this->duplicate_product( $this->get_product_to_duplicate( $child->ID ), $new_post_id, $child->post_status );
}
if ( ! $exclude && ( $children_products = get_children( 'post_parent=' . $post->ID . '&post_type=product_variation' ) ) ) {
foreach ( $children_products as $child ) {
$this->duplicate_product( $this->get_product_to_duplicate( $child->ID ), $new_post_id, $child->post_status );
}
}
@ -216,16 +214,15 @@ class WC_Admin_Duplicate_Product {
* @param mixed $post_type
*/
private function duplicate_post_taxonomies( $id, $new_id, $post_type ) {
$taxonomies = get_object_taxonomies( $post_type );
$exclude = array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_taxonomies', array() ) );
$taxonomies = array_diff( get_object_taxonomies( $post_type ), $exclude );
foreach ( $taxonomies as $taxonomy ) {
$post_terms = wp_get_object_terms( $id, $taxonomy );
$post_terms = wp_get_object_terms( $id, $taxonomy );
$post_terms_count = sizeof( $post_terms );
for ( $i=0; $i<$post_terms_count; $i++ ) {
wp_set_object_terms( $new_id, $post_terms[$i]->slug, $taxonomy, true );
for ( $i = 0; $i < $post_terms_count; $i++ ) {
wp_set_object_terms( $new_id, $post_terms[ $i ]->slug, $taxonomy, true );
}
}
}
@ -239,22 +236,26 @@ class WC_Admin_Duplicate_Product {
private function duplicate_post_meta( $id, $new_id ) {
global $wpdb;
$post_meta_infos = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d AND meta_key NOT IN ( 'total_sales' );", absint( $id ) ) );
$exclude = array_map( 'esc_sql', array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_meta', array( 'total_sales' ) ) ) );
if ( count( $post_meta_infos ) != 0 ) {
if ( sizeof( $exclude ) ) {
$post_meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d AND meta_key NOT IN ( '" . implode( "','", $exclude ) . "' );", absint( $id ) ) );
} else {
$post_meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d;", absint( $id ) ) );
}
if ( sizeof( $post_meta ) ) {
$sql_query_sel = array();
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
foreach ( $post_meta_infos as $meta_info ) {
$sql_query_sel[]= $wpdb->prepare( "SELECT %d, %s, %s", $new_id, $meta_info->meta_key, $meta_info->meta_value );
foreach ( $post_meta as $post_meta_row ) {
$sql_query_sel[] = $wpdb->prepare( "SELECT %d, %s, %s", $new_id, $post_meta_row->meta_key, $post_meta_row->meta_value );
}
$sql_query.= implode( " UNION ALL ", $sql_query_sel );
$wpdb->query($sql_query);
$sql_query .= implode( " UNION ALL ", $sql_query_sel );
$wpdb->query( $sql_query );
}
}
}
endif;

View File

@ -52,11 +52,11 @@ class WC_Admin_Help {
'title' => __( 'Support', 'woocommerce' ),
'content' =>
'<p>' . sprintf( __( 'After %sreading the documentation%s, for further assistance you can use our %scommunity forum%s if you get stuck. For help with premium add-ons from WooThemes, or if you are a WooThemes customer, you can %suse our helpdesk%s.', 'woocommerce' ), '<a href="http://docs.woothemes.com/documentation/plugins/woocommerce/">', '</a>', '<a href="https://support.woothemes.com/hc/communities/public/topics">', '</a>', '<a href="http://support.woothemes.com">', '</a>' ) . '</p>' .
'<p>' . sprintf( __( 'After %sreading the documentation%s, for further assistance you can use the %sWordPress.org support forum%s. For help with premium add-ons from WooThemes, or if you are a WooThemes customer, you can %suse our helpdesk%s.', 'woocommerce' ), '<a href="http://docs.woothemes.com/documentation/plugins/woocommerce/">', '</a>', '<a href="https://wordpress.org/support/plugin/woocommerce">', '</a>', '<a href="http://support.woothemes.com">', '</a>' ) . '</p>' .
'<p>' . __( 'Before asking for help we recommend checking the status page to identify any problems with your configuration.', 'woocommerce' ) . '</p>' .
'<p><a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button button-primary">' . __( 'System Status', 'woocommerce' ) . '</a> <a href="' . 'https://support.woothemes.com/hc/communities/public/topics' . '" class="button">' . __( 'WooThemes Community Support', 'woocommerce' ) . '</a> <a href="' . 'http://support.woothemes.com' . '" class="button">' . __( 'WooThemes Customer Support', 'woocommerce' ) . '</a></p>'
'<p><a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button button-primary">' . __( 'System Status', 'woocommerce' ) . '</a> <a href="' . 'https://wordpress.org/support/plugin/woocommerce' . '" class="button">' . __( 'WordPress.org Support Forum', 'woocommerce' ) . '</a> <a href="' . 'http://support.woothemes.com' . '" class="button">' . __( 'WooThemes Customer Support', 'woocommerce' ) . '</a></p>'
) );

View File

@ -1351,6 +1351,7 @@ class WC_Admin_Post_Types {
foreach ( $post_ids as $post_id ) {
$order = wc_get_order( $post_id );
$order->update_status( $new_status, __( 'Order status changed by bulk edit:', 'woocommerce' ) );
do_action( 'woocommerce_order_edit_status', $post_id, $new_status );
$changed++;
}

View File

@ -800,6 +800,7 @@ class WC_Meta_Box_Product_Data {
$variation_data['_thumbnail_id'] = absint( $variation_data['_thumbnail_id'] );
$variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url( $variation_data['_thumbnail_id'] ) : '';
$variation_data['shipping_class'] = $shipping_classes && ! is_wp_error( $shipping_classes ) ? current( $shipping_classes )->term_id : '';
$variation_data['_stock'] = wc_stock_amount( $variation_data['_stock'] );
// Stock BW compat
if ( '' !== $variation_data['_stock'] ) {
@ -981,7 +982,7 @@ class WC_Meta_Box_Product_Data {
$attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
$attribute_position = $_POST['attribute_position'];
$attribute_names_max_key = max( $attribute_names );
$attribute_names_max_key = max( array_keys( $attribute_names ) );
for ( $i = 0; $i <= $attribute_names_max_key; $i++ ) {
if ( empty( $attribute_names[ $i ] ) ) {
@ -1250,7 +1251,7 @@ class WC_Meta_Box_Product_Data {
// Validate the file extension
if ( in_array( $file_is, array( 'absolute', 'relative' ) ) ) {
$file_type = wp_check_filetype( $file_url );
$file_type = wp_check_filetype( strtok( $file_url, '?' ) );
$parsed_url = parse_url( $file_url, PHP_URL_PATH );
$extension = pathinfo( $parsed_url, PATHINFO_EXTENSION );
@ -1261,7 +1262,7 @@ class WC_Meta_Box_Product_Data {
}
// Validate the file exists
if ( 'relative' === $file_is && ! file_exists( $file_url ) ) {
if ( 'relative' === $file_is && ! apply_filters( 'woocommerce_downloadable_file_exists', file_exists( $file_url ), $file_url ) ) {
WC_Admin_Meta_Boxes::add_error( sprintf( __( 'The downloadable file %s cannot be used as it does not exist on the server.', 'woocommerce' ), '<code>' . $file_url . '</code>' ) );
continue;
}
@ -1524,7 +1525,7 @@ class WC_Meta_Box_Product_Data {
// Validate the file extension
if ( in_array( $file_is, array( 'absolute', 'relative' ) ) ) {
$file_type = wp_check_filetype( $file_url );
$file_type = wp_check_filetype( strtok( $file_url, '?' ) );
$parsed_url = parse_url( $file_url, PHP_URL_PATH );
$extension = pathinfo( $parsed_url, PATHINFO_EXTENSION );
@ -1535,7 +1536,7 @@ class WC_Meta_Box_Product_Data {
}
// Validate the file exists
if ( 'relative' === $file_is && ! file_exists( $file_url ) ) {
if ( 'relative' === $file_is && ! apply_filters( 'woocommerce_downloadable_file_exists', file_exists( $file_url ), $file_url ) ) {
WC_Admin_Meta_Boxes::add_error( sprintf( __( 'The downloadable file %s cannot be used as it does not exist on the server.', 'woocommerce' ), '<code>' . $file_url . '</code>' ) );
continue;
}
@ -1558,7 +1559,7 @@ class WC_Meta_Box_Product_Data {
}
update_post_meta( $variation_id, '_variation_description', wp_kses_post( $variable_description[ $i ] ) );
// Save shipping class
$variable_shipping_class[ $i ] = ! empty( $variable_shipping_class[ $i ] ) ? (int) $variable_shipping_class[ $i ] : '';
wp_set_object_terms( $variation_id, $variable_shipping_class[ $i ], 'product_shipping_class');

View File

@ -4,11 +4,12 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<input type="hidden" name="key_id" value="<?php echo esc_attr( $key_id ); ?>" />
<div id="key-fields" class="settings-panel">
<h3><?php _e( 'Key Details', 'woocommerce' ); ?></h3>
<table class="form-table">
<input type="hidden" id="key_id" value="<?php echo esc_attr( $key_id ); ?>" />
<table id="api-keys-options" class="form-table">
<tbody>
<tr valign="top">
<th scope="row" class="titledesc">
@ -16,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<img class="help_tip" data-tip="<?php esc_attr_e( 'Friendly name for identifying this key.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</th>
<td class="forminp">
<input name="key_description" id="key_description" type="text" class="input-text regular-input" value="<?php echo esc_attr( $key_data['description'] ); ?>" />
<input id="key_description" type="text" class="input-text regular-input" value="<?php echo esc_attr( $key_data['description'] ); ?>" />
</td>
</tr>
<tr valign="top">
@ -31,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) {
$user = get_user_by( 'id', $user_id );
$user_string = esc_html( $user->display_name ) . ' (#' . absint( $user->ID ) . ' &ndash; ' . esc_html( $user->user_email );
?>
<input type="hidden" class="wc-customer-search" name="key_user" data-placeholder="<?php esc_html_e( 'Search for a customer&hellip;', 'woocommerce' ); ?>" data-selected="<?php echo esc_attr( $user_string ); ?>" value="<?php echo esc_attr( $user_id ); ?>" data-allow_clear="true" />
<input type="hidden" class="wc-customer-search" id="key_user" data-placeholder="<?php esc_html_e( 'Search for a customer&hellip;', 'woocommerce' ); ?>" data-selected="<?php echo esc_attr( $user_string ); ?>" value="<?php echo esc_attr( $user_id ); ?>" data-allow_clear="true" />
</td>
</tr>
<tr valign="top">
@ -40,7 +41,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<img class="help_tip" data-tip="<?php _e( 'Select the access type of these keys.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</th>
<td class="forminp">
<select name="key_permissions" id="key_permissions" class="wc-enhanced-select">
<select id="key_permissions" class="wc-enhanced-select">
<?php
$permissions = array(
'read' => __( 'Read', 'woocommerce' ),
@ -54,59 +55,6 @@ if ( ! defined( 'ABSPATH' ) ) {
</select>
</td>
</tr>
<?php if ( ! empty( $key_data['consumer_key'] ) && ! empty( $key_data['consumer_secret'] ) ) : ?>
<tr valign="top" id="webhook-action-event-wrap">
<th scope="row" class="titledesc">
<?php _e( 'Consumer Key', 'woocommerce' ); ?>
</th>
<td class="forminp">
<code id="key_consumer_key"><?php echo esc_html( $key_data['consumer_key'] ); ?></code> <button type="button" class="button-secondary copy-key" data-tip="<?php _e( 'Copied!', 'woocommerce' ); ?>"><?php _e( 'Copy', 'woocommerce' ); ?></button>
</td>
</tr>
<tr valign="top" id="webhook-action-event-wrap">
<th scope="row" class="titledesc">
<label for="key_consumer_secret"><?php _e( 'Consumer Secret', 'woocommerce' ); ?></label>
</th>
<td class="forminp">
<code id="key_consumer_secret"><?php echo esc_html( $key_data['consumer_secret'] ); ?></code> <button type="button" class="button-secondary copy-key" data-tip="<?php _e( 'Copied!', 'woocommerce' ); ?>"><?php _e( 'Copy', 'woocommerce' ); ?></button>
</td>
</tr>
<tr valign="top" id="webhook-action-event-wrap">
<th scope="row" class="titledesc">
<?php _e( 'QRCode', 'woocommerce' ); ?>
</th>
<td class="forminp">
<div id="qrcode_wrap" data-consumer_key="<?php echo esc_attr( $key_data['consumer_key'] ); ?>" data-consumer_secret="<?php echo esc_attr( $key_data['consumer_secret'] ); ?>"></div>
<script>
jQuery( function( $ ) {
// Copy to clipboard
$( '.copy-key' ).tipTip({
'attribute': 'data-tip',
'activation': 'click',
'fadeIn': 50,
'fadeOut': 50,
'delay': 0
});
$( document.body ).on( 'copy', '.copy-key', function( e ) {
e.clipboardData.clearData();
e.clipboardData.setData( 'text/plain', $.trim( $( this ).prev( 'code' ).html() ) );
e.preventDefault();
});
// Generate QR Code
var qrcodeWrap = $( '#qrcode_wrap' );
qrcodeWrap.qrcode({
text: qrcodeWrap.data( 'consumer_key' ) + '|' + qrcodeWrap.data( 'consumer_secret' ),
width: 120,
height: 120
});
});
</script>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
@ -125,3 +73,34 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
</div>
<script type="text/template" id="api-keys-template">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Consumer Key', 'woocommerce' ); ?>
</th>
<td class="forminp">
<code id="key_consumer_key"><%- consumer_key %></code> <button type="button" class="button-secondary copy-key" data-tip="<?php _e( 'Copied!', 'woocommerce' ); ?>"><?php _e( 'Copy', 'woocommerce' ); ?></button>
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="key_consumer_secret"><?php _e( 'Consumer Secret', 'woocommerce' ); ?></label>
</th>
<td class="forminp">
<code id="key_consumer_secret"><%- consumer_secret %></code> <button type="button" class="button-secondary copy-key" data-tip="<?php _e( 'Copied!', 'woocommerce' ); ?>"><?php _e( 'Copy', 'woocommerce' ); ?></button>
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'QRCode', 'woocommerce' ); ?>
</th>
<td class="forminp">
<div id="keys-qrcode"></div>
</td>
</tr>
</tbody>
</table>
</script>

View File

@ -169,11 +169,13 @@ class WC_API_Authentication {
private function get_keys_by_consumer_key( $consumer_key ) {
global $wpdb;
$consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );
$keys = $wpdb->get_row( $wpdb->prepare( "
SELECT *
FROM {$wpdb->prefix}woocommerce_api_keys
WHERE consumer_key = '%s'
", sanitize_text_field( $consumer_key ) ), ARRAY_A );
", $consumer_key ), ARRAY_A );
if ( empty( $keys ) ) {
throw new Exception( __( 'Consumer Key is invalid', 'woocommerce' ), 401 );

View File

@ -361,14 +361,10 @@ class WC_API_Customers extends WC_API_Resource {
}
// Sets the username.
if ( ! isset( $data['username'] ) ) {
$data['username'] = '';
}
$data['username'] = ! empty( $data['username'] ) ? $data['username'] : '';
// Sets the password.
if ( ! isset( $data['password'] ) ) {
$data['password'] = wp_generate_password();
}
$data['password'] = ! empty( $data['password'] ) ? $data['password'] : '';
// Attempts to create the new customer
$id = wc_create_new_customer( $data['email'], $data['username'], $data['password'] );

View File

@ -241,9 +241,9 @@ class WC_API_Orders extends WC_API_Resource {
$order_data['line_items'][] = array(
'id' => $item_id,
'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ),
'subtotal_tax' => wc_format_decimal( wc_round_tax_total( $item['line_subtotal_tax'] ), $dp ),
'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ),
'total' => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ),
'total_tax' => wc_format_decimal( $order->get_line_tax( $item ), $dp ),
'total_tax' => wc_format_decimal( $item['line_tax'], $dp ),
'price' => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ),
'quantity' => wc_stock_amount( $item['qty'] ),
'tax_class' => ( ! empty( $item['tax_class'] ) ) ? $item['tax_class'] : null,
@ -897,12 +897,25 @@ class WC_API_Orders extends WC_API_Resource {
}
if ( isset( $item['product_id'] ) ) {
$product = wc_get_product( $item['product_id'] );
$product_id = $item['product_id'];
} elseif ( isset( $item['sku'] ) ) {
$product_id = wc_get_product_id_by_sku( $item['sku'] );
$product = wc_get_product( $product_id );
}
// variations must each have a key & value
$variation_id = 0;
if ( isset( $item['variations'] ) && is_array( $item['variations'] ) ) {
foreach ( $item['variations'] as $key => $value ) {
if ( ! $key || ! $value ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_product_variation', __( 'The product variation is invalid', 'woocommerce' ), 400 );
}
}
$item_args['variation'] = $item['variations'];
$variation_id = $this->get_variation_id( wc_get_product( $product_id ), $item_args['variation'] );
}
$product = wc_get_product( $variation_id ? $variation_id : $product_id );
// must be a valid WC_Product
if ( ! is_object( $product ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_product', __( 'Product is invalid', 'woocommerce' ), 400 );
@ -925,16 +938,6 @@ class WC_API_Orders extends WC_API_Resource {
$item_args['qty'] = $item['quantity'];
}
// variations must each have a key & value
if ( isset( $item['variations'] ) && is_array( $item['variations'] ) ) {
foreach ( $item['variations'] as $key => $value ) {
if ( ! $key || ! $value ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_product_variation', __( 'The product variation is invalid', 'woocommerce' ), 400 );
}
}
$item_args['variation'] = $item['variations'];
}
// total
if ( isset( $item['total'] ) ) {
$item_args['totals']['total'] = floatval( $item['total'] );
@ -973,6 +976,56 @@ class WC_API_Orders extends WC_API_Resource {
}
}
/**
* Given a product ID & API provided variations, find the correct variation ID to use for calculation
* We can't just trust input from the API to pass a variation_id manually, otherwise you could pass
* the cheapest variation ID but provide other information so we have to look up the variation ID.
* @param int $product_id main product ID
* @return int returns an ID if a valid variation was found for this product
*/
function get_variation_id( $product, $variations = array() ) {
$variation_id = null;
$variations_normalized = array();
if ( $product->is_type( 'variable' ) && $product->has_child() ) {
if ( isset( $variations ) && is_array( $variations ) ) {
// start by normalizing the passed variations
foreach ( $variations as $key => $value ) {
$key = str_replace( 'attribute_', '', str_replace( 'pa_', '', $key ) ); // from get_attributes in class-wc-api-products.php
$variations_normalized[ $key ] = strtolower( $value );
}
// now search through each product child and see if our passed variations match anything
foreach ( $product->get_children() as $variation ) {
$meta = array();
foreach ( get_post_meta( $variation ) as $key => $value ) {
$value = $value[0];
$key = str_replace( 'attribute_', '', str_replace( 'pa_', '', $key ) );
$meta[ $key ] = strtolower( $value );
}
// if the variation array is a part of the $meta array, we found our match
if ( $this->array_contains( $variations_normalized, $meta ) ) {
$variation_id = $variation;
break;
}
}
}
}
return $variation_id;
}
/**
* Utility function to see if the meta array contains data from variations
*/
protected function array_contains( $needles, $haystack ) {
foreach ( $needles as $key => $value ) {
if ( $haystack[ $key ] !== $value ) {
return false;
}
}
return true;
}
/**
* Create or update an order shipping method
*

View File

@ -534,13 +534,26 @@ class WC_API_Products extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_product_category_id', __( 'A product category with the provided ID could not be found', 'woocommerce' ), 404 );
}
$term_id = intval( $term->term_id );
// Get category display type
$display_type = get_woocommerce_term_meta( $term_id, 'display_type' );
// Get category image
$image = '';
if ( $image_id = get_woocommerce_term_meta( $term_id, 'thumbnail_id' ) ) {
$image = wp_get_attachment_url( $image_id );
}
$product_category = array(
'id' => intval( $term->term_id ),
'id' => $term_id,
'name' => $term->name,
'slug' => $term->slug,
'parent' => $term->parent,
'description' => $term->description,
'count' => intval( $term->count ),
'display' => $display_type ? $display_type : 'default',
'image' => $image ? esc_url( $image ) : '',
'count' => intval( $term->count )
);
return array( 'product_category' => apply_filters( 'woocommerce_api_product_category_response', $product_category, $id, $fields, $term, $this ) );
@ -1590,7 +1603,12 @@ class WC_API_Products extends WC_API_Resource {
}
$file_name = isset( $file['name'] ) ? wc_clean( $file['name'] ) : '';
$file_url = wc_clean( $file['file'] );
if ( 0 === strpos( $file['file'], 'http' ) ) {
$file_url = esc_url_raw( $file['file'] );
} else {
$file_url = wc_clean( $file['file'] );
}
$files[ md5( $file_url ) ] = array(
'name' => $file_name,
@ -1721,7 +1739,7 @@ class WC_API_Products extends WC_API_Resource {
$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
if ( 0 === $attachment_id && isset( $image['src'] ) ) {
$upload = $this->upload_product_image( wc_clean( $image['src'] ) );
$upload = $this->upload_product_image( esc_url_raw( $image['src'] ) );
if ( is_wp_error( $upload ) ) {
throw new WC_API_Exception( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), 400 );
@ -1735,7 +1753,7 @@ class WC_API_Products extends WC_API_Resource {
$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
if ( 0 === $attachment_id && isset( $image['src'] ) ) {
$upload = $this->upload_product_image( wc_clean( $image['src'] ) );
$upload = $this->upload_product_image( esc_url_raw( $image['src'] ) );
if ( is_wp_error( $upload ) ) {
throw new WC_API_Exception( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), 400 );

View File

@ -459,6 +459,7 @@ class WC_API_Server {
'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
'ssl_enabled' => ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ),
'permalinks_enabled' => ( '' !== get_option( 'permalink_structure' ) ),
'generate_password' => ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) ),
'links' => array(
'help' => 'http://woothemes.github.io/woocommerce-rest-api-docs/',
),
@ -564,10 +565,16 @@ class WC_API_Server {
// WP_User_Query
if ( is_a( $query, 'WP_User_Query' ) ) {
$page = $query->page;
$single = count( $query->get_results() ) == 1;
$total = $query->get_total();
$total_pages = $query->total_pages;
if( $query->get( 'number' ) > 0 ) {
$page = ( $query->get( 'offset' ) / $query->get( 'number' ) ) + 1;
$total_pages = ceil( $total / $query->get( 'number' ) );
} else {
$page = 1;
$total_pages = 1;
}
// WP_Query
} else {

View File

@ -169,11 +169,13 @@ class WC_API_Authentication {
private function get_keys_by_consumer_key( $consumer_key ) {
global $wpdb;
$consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );
$keys = $wpdb->get_row( $wpdb->prepare( "
SELECT *
FROM {$wpdb->prefix}woocommerce_api_keys
WHERE consumer_key = '%s'
", sanitize_text_field( $consumer_key ) ), ARRAY_A );
", $consumer_key ), ARRAY_A );
if ( empty( $keys ) ) {
throw new Exception( __( 'Consumer Key is invalid', 'woocommerce' ), 401 );

View File

@ -128,7 +128,8 @@ class WC_AJAX {
'product_ordering' => false,
'refund_line_items' => false,
'delete_refund' => false,
'rated' => false
'rated' => false,
'update_api_key' => false
);
foreach ( $ajax_events as $ajax_event => $nopriv ) {
@ -465,6 +466,7 @@ class WC_AJAX {
if ( wc_is_order_status( 'wc-' . $status ) && $order_id ) {
$order = wc_get_order( $order_id );
$order->update_status( $status );
do_action( 'woocommerce_order_edit_status', $order_id, $status );
}
}
@ -604,7 +606,7 @@ class WC_AJAX {
$attribute_is_taxonomy = $data['attribute_is_taxonomy'];
$attribute_position = $data['attribute_position'];
$attribute_names_max_key = max( $attribute_names );
$attribute_names_max_key = max( array_keys( $attribute_names ) );
for ( $i = 0; $i <= $attribute_names_max_key; $i++ ) {
if ( empty( $attribute_names[ $i ] ) ) {
@ -966,7 +968,7 @@ class WC_AJAX {
}
}
delete_transient( 'wc_product_children_ids_' . $post_id . WC_Cache_Helper::get_transient_version( 'product' ) );
delete_transient( 'wc_product_children' . $post_id . WC_Cache_Helper::get_transient_version( 'product' ) );
echo $added;
@ -1338,9 +1340,10 @@ class WC_AJAX {
if ( $_product->exists() && $_product->managing_stock() && isset( $order_item_qty[ $item_id ] ) && $order_item_qty[ $item_id ] > 0 ) {
$stock_change = apply_filters( 'woocommerce_reduce_order_stock_quantity', $order_item_qty[ $item_id ], $item_id );
$new_stock = $_product->reduce_stock( $stock_change );
$note = sprintf( __( 'Item #%s stock reduced from %s to %s.', 'woocommerce' ), $order_item['product_id'], $new_stock + $stock_change, $new_stock );
$return[] = $note;
$return[] = sprintf( __( 'Item #%s stock reduced from %s to %s.', 'woocommerce' ), $order_item['product_id'], $new_stock + $stock_change, $new_stock );
$order->add_order_note( sprintf( __( 'Item #%s stock reduced from %s to %s.', 'woocommerce' ), $order_item['product_id'], $new_stock + $stock_change, $new_stock ) );
$order->add_order_note( $note );
$order->send_stock_notifications( $_product, $new_stock, $order_item_qty[ $item_id ] );
}
}
@ -1386,13 +1389,13 @@ class WC_AJAX {
$_product = $order->get_product_from_item( $order_item );
if ( $_product->exists() && $_product->managing_stock() && isset( $order_item_qty[ $item_id ] ) && $order_item_qty[ $item_id ] > 0 ) {
$old_stock = $_product->stock;
$stock_change = apply_filters( 'woocommerce_restore_order_stock_quantity', $order_item_qty[ $item_id ], $item_id );
$new_quantity = $_product->increase_stock( $stock_change );
$note = sprintf( __( 'Item #%s stock increased from %s to %s.', 'woocommerce' ), $order_item['product_id'], $old_stock, $new_quantity );
$return[] = $note;
$return[] = sprintf( __( 'Item #%s stock increased from %s to %s.', 'woocommerce' ), $order_item['product_id'], $old_stock, $new_quantity );
$order->add_order_note( sprintf( __( 'Item #%s stock increased from %s to %s.', 'woocommerce' ), $order_item['product_id'], $old_stock, $new_quantity ) );
$order->add_order_note( $note );
}
}
@ -1708,10 +1711,6 @@ class WC_AJAX {
check_ajax_referer( 'search-products', 'security' );
if ( ! current_user_can( 'edit_products' ) ) {
die(-1);
}
$term = (string) wc_clean( stripslashes( $_GET['term'] ) );
if ( empty( $term ) ) {
@ -1786,6 +1785,10 @@ class WC_AJAX {
foreach ( $posts as $post ) {
$product = wc_get_product( $post );
if ( ! current_user_can( 'read_product', $post ) ) {
continue;
}
$found_products[ $post ] = rawurldecode( $product->get_formatted_name() );
}
}
@ -1860,10 +1863,6 @@ class WC_AJAX {
check_ajax_referer( 'search-products', 'security' );
if ( ! current_user_can( 'edit_products' ) ) {
die(-1);
}
$term = (string) wc_clean( stripslashes( $_GET['term'] ) );
$args = array(
@ -1887,6 +1886,11 @@ class WC_AJAX {
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
$product = wc_get_product( $post->ID );
if ( ! current_user_can( 'read_product', $post->ID ) ) {
continue;
}
$found_products[ $post->ID ] = $product->get_formatted_name();
}
}
@ -2183,6 +2187,96 @@ class WC_AJAX {
update_option( 'woocommerce_admin_footer_text_rated', 1 );
die();
}
/**
* Create/Update API key
*/
public static function update_api_key() {
ob_start();
global $wpdb;
check_ajax_referer( 'update-api-key', 'security' );
if ( ! current_user_can( 'manage_woocommerce' ) ) {
die(-1);
}
try {
if ( empty( $_POST['description'] ) ) {
throw new Exception( __( 'Description is missing.', 'woocommerce' ) );
}
if ( empty( $_POST['user'] ) ) {
throw new Exception( __( 'User is missing.', 'woocommerce' ) );
}
if ( empty( $_POST['permissions'] ) ) {
throw new Exception( __( 'Permissions is missing.', 'woocommerce' ) );
}
$key_id = absint( $_POST['key_id'] );
$description = sanitize_text_field( $_POST['description'] );
$permissions = ( in_array( $_POST['permissions'], array( 'read', 'write', 'read_write' ) ) ) ? sanitize_text_field( $_POST['permissions'] ) : 'read';
$user_id = absint( $_POST['user'] );
if ( 0 < $key_id ) {
$data = array(
'user_id' => $user_id,
'description' => $description,
'permissions' => $permissions
);
$wpdb->update(
$wpdb->prefix . 'woocommerce_api_keys',
$data,
array( 'key_id' => $key_id ),
array(
'%d',
'%s',
'%s'
),
array( '%d' )
);
$data['consumer_key'] = '';
$data['consumer_secret'] = '';
$data['message'] = __( 'API Key updated successfully.', 'woocommerce' );
} else {
$status = 2;
$consumer_key = 'ck_' . wc_rand_hash();
$consumer_secret = 'cs_' . wc_rand_hash();
$data = array(
'user_id' => $user_id,
'description' => $description,
'permissions' => $permissions,
'consumer_key' => wc_api_hash( $consumer_key ),
'consumer_secret' => $consumer_secret
);
$wpdb->insert(
$wpdb->prefix . 'woocommerce_api_keys',
$data,
array(
'%d',
'%s',
'%s',
'%s',
'%s'
)
);
$key_id = $wpdb->insert_id;
$data['consumer_key'] = $consumer_key;
$data['consumer_secret'] = $consumer_secret;
$data['message'] = __( 'API Key generated successfully. Make sure to copy your new API keys now. You won\'t be able to see it again!', 'woocommerce' );
$data['revoke_url'] = '<a style="color: #a00; text-decoration: none;" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ). '">' . __( 'Revoke Key', 'woocommerce' ) . '</a>';
}
wp_send_json_success( $data );
} catch ( Exception $e ) {
wp_send_json_error( array( 'message' => $e->getMessage() ) );
}
}
}
WC_AJAX::init();

View File

@ -36,7 +36,6 @@ class WC_API {
* @return WC_API
*/
public function __construct() {
// add query vars
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
@ -48,6 +47,9 @@ class WC_API {
// handle wc-api endpoint requests
add_action( 'parse_request', array( $this, 'handle_api_requests' ), 0 );
// Ensure payment gateways are initialized in time for API requests
add_action( 'woocommerce_api_request', array( 'WC_Payment_Gateways', 'instance' ), 0 );
}
/**
@ -228,9 +230,10 @@ class WC_API {
}
/**
* API request - Trigger any API requests
* API request - Trigger any API requests.
*
* @since 2.0
* @since 2.0
* @version 2.4
*/
public function handle_api_requests() {
global $wp;
@ -245,20 +248,24 @@ class WC_API {
// Buffer, we won't want any output here
ob_start();
// Get API trigger
$api = strtolower( esc_attr( $wp->query_vars['wc-api'] ) );
// No cache headers
nocache_headers();
// Load class if exists
if ( class_exists( $api ) ) {
new $api();
}
// Clean the API request
$api_request = strtolower( wc_clean( $wp->query_vars['wc-api'] ) );
// Trigger actions
do_action( 'woocommerce_api_' . $api );
// Trigger generic action before request hook
do_action( 'woocommerce_api_request', $api_request );
// Is there actually something hooked into this API request? If not trigger 400 - Bad request
status_header( has_action( 'woocommerce_api_' . $api_request ) ? 200 : 400 );
// Trigger an action which plugins can hook into to fulfill the request
do_action( 'woocommerce_api_' . $api_request );
// Done, clear buffer and exit
ob_end_clean();
die('1');
die('-1');
}
}
}

View File

@ -194,8 +194,8 @@ class WC_Auth {
// Created API keys.
$permissions = ( in_array( $scope, array( 'read', 'write', 'read_write' ) ) ) ? sanitize_text_field( $scope ) : 'read';
$consumer_key = 'ck_' . hash( 'md5', $user->user_login . date( 'U' ) . mt_rand() );
$consumer_secret = 'cs_' . hash( 'md5', $user->ID . date( 'U' ) . mt_rand() );
$consumer_key = 'ck_' . wc_rand_hash();
$consumer_secret = 'cs_' . wc_rand_hash();
$wpdb->insert(
$wpdb->prefix . 'woocommerce_api_keys',
@ -203,7 +203,7 @@ class WC_Auth {
'user_id' => $user->ID,
'description' => $description,
'permissions' => $permissions,
'consumer_key' => $consumer_key,
'consumer_key' => wc_api_hash( $consumer_key ),
'consumer_secret' => $consumer_secret
),
array(

View File

@ -1832,14 +1832,15 @@ class WC_Cart {
$total_discount = $discount_amount * $values['quantity'];
$total_discount_tax = 0;
// Calc discounted tax
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
$taxes = WC_Tax::calc_tax( $discount_amount, $tax_rates, $this->prices_include_tax );
$total_discount_tax = WC_Tax::get_tax_total( $taxes ) * $values['quantity'];
$total_discount = $this->prices_include_tax ? $total_discount - $total_discount_tax : $total_discount;
if ( wc_tax_enabled() ) {
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
$taxes = WC_Tax::calc_tax( $discount_amount, $tax_rates, $this->prices_include_tax );
$total_discount_tax = WC_Tax::get_tax_total( $taxes ) * $values['quantity'];
$total_discount = $this->prices_include_tax ? $total_discount - $total_discount_tax : $total_discount;
$this->discount_cart_tax += $total_discount_tax;
}
$this->discount_cart += $total_discount;
$this->discount_cart_tax += $total_discount_tax;
$this->increase_coupon_discount_amount( $code, $total_discount, $total_discount_tax );
$this->increase_coupon_applied_count( $code, $values['quantity'] );
}

View File

@ -581,7 +581,11 @@ class WC_Coupon {
if ( $this->exclude_sale_items == 'yes' ) {
$product_ids_on_sale = wc_get_product_ids_on_sale();
if ( in_array( $product->id, $product_ids_on_sale, true ) || ( isset( $product->variation_id ) && in_array( $product->variation_id, $product_ids_on_sale, true ) ) || in_array( $product->get_parent(), $product_ids_on_sale, true ) ) {
if ( isset( $product->variation_id ) ) {
if ( in_array( $product->variation_id, $product_ids_on_sale, true ) ) {
$valid = false;
}
} elseif ( in_array( $product->id, $product_ids_on_sale, true ) ) {
$valid = false;
}
}

View File

@ -346,8 +346,8 @@ CREATE TABLE {$wpdb->prefix}woocommerce_api_keys (
user_id bigint(20) NOT NULL,
description longtext NULL,
permissions varchar(10) NOT NULL,
consumer_key varchar(200) NOT NULL,
consumer_secret varchar(200) NOT NULL,
consumer_key char(64) NOT NULL,
consumer_secret char(43) NOT NULL,
nonces longtext NULL,
PRIMARY KEY (key_id),
KEY consumer_key (consumer_key),

View File

@ -86,7 +86,7 @@ class WC_Product_Grouped extends WC_Product {
*/
public function get_children() {
if ( ! is_array( $this->children ) || empty( $this->children ) ) {
$transient_name = 'wc_product_children_ids_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
$transient_name = 'wc_product_children' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
$this->children = get_transient( $transient_name );
if ( empty( $this->children ) ) {

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Product_Variable extends WC_Product {
/** @public array Array of child products/posts/variations. */
public $children;
public $children = null;
/** @public string The product's total stock, including that of its children. */
public $total_stock;
@ -81,7 +81,7 @@ class WC_Product_Variable extends WC_Product {
*/
public function set_stock( $amount = null, $mode = 'set' ) {
$this->total_stock = '';
delete_transient( 'wc_product_total_stock_' . $this->id );
delete_transient( 'wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' ) );
return parent::set_stock( $amount, $mode );
}
@ -124,49 +124,53 @@ class WC_Product_Variable extends WC_Product {
}
/**
* Return the products children posts.
* Return a products child ids.
*
* @param boolean $visible_only Only return variations which are not hidden
* @return array of children ids
*/
public function get_children( $visible_only = false ) {
if ( ! is_array( $this->children ) || empty( $this->children ) ) {
$transient_name = 'wc_product_children_ids_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
$key = $visible_only ? 'visible' : 'all';
$transient_name = 'wc_product_children' . $this->id . WC_Cache_Helper::get_transient_version( 'product' );
// Get value of transient
if ( ! is_array( $this->children ) ) {
$this->children = get_transient( $transient_name );
}
if ( empty( $this->children ) ) {
$args = array(
'post_parent' => $this->id,
'post_type' => 'product_variation',
'orderby' => 'menu_order',
'order' => 'ASC',
'fields' => 'ids',
'post_status' => 'publish',
'numberposts' => -1
// Get value from DB
if ( empty( $this->children ) || ! is_array( $this->children ) || ! isset( $this->children[ $key ] ) ) {
$args = array(
'post_parent' => $this->id,
'post_type' => 'product_variation',
'orderby' => 'menu_order',
'order' => 'ASC',
'fields' => 'ids',
'post_status' => 'publish',
'numberposts' => -1
);
if ( $visible_only ) {
$args['meta_query'] = array(
'relation' => 'AND',
// Price is required
array(
'key' => '_price',
'value' => '',
'compare' => '!=',
),
// Must be in stock
array(
'key' => '_stock_status',
'value' => 'instock',
'compare' => '=',
)
);
$this->children = get_posts( $args );
set_transient( $transient_name, $this->children, DAY_IN_SECONDS * 30 );
}
$this->children[ $key ] = get_posts( $args );
set_transient( $transient_name, $this->children, DAY_IN_SECONDS * 30 );
}
if ( $visible_only ) {
$children = array();
foreach( $this->children as $child_id ) {
if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) {
if ( 'instock' === get_post_meta( $child_id, '_stock_status', true ) ) {
$children[] = $child_id;
}
} elseif ( $this->is_in_stock() ) {
$children[] = $child_id;
}
}
} else {
$children = $this->children;
}
return apply_filters( 'woocommerce_get_children', $children, $this );
return apply_filters( 'woocommerce_get_children', $this->children[ $key ], $this, $visible_only );
}
/**
@ -259,18 +263,11 @@ class WC_Product_Variable extends WC_Product {
$regular_prices = array();
$sale_prices = array();
$tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
$hide_out_of_stock = 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' );
foreach ( $this->get_children() as $variation_id ) {
foreach ( $this->get_children( true ) as $variation_id ) {
$price = get_post_meta( $variation_id, '_price', true );
$regular_price = get_post_meta( $variation_id, '_regular_price', true );
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
$stock = get_post_meta( $variation_id, '_stock', true );
// Skip hidden and non priced variations
if ( '' === $price || ( $hide_out_of_stock && '' !== $stock && $stock <= get_option( 'woocommerce_notify_no_stock_amount' ) ) ) {
continue;
}
// If sale price does not equal price, the product is not yet on sale
if ( $price != $sale_price ) {

View File

@ -443,7 +443,7 @@ class WC_Product_Variation extends WC_Product {
wp_cache_delete( $this->variation_id, 'post_meta' );
// Clear total stock transient
delete_transient( 'wc_product_total_stock_' . $this->id );
delete_transient( 'wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version( 'product' ) );
// Stock status
$this->check_stock_status();

View File

@ -113,7 +113,7 @@ class WC_Query {
break;
case 'view-order' :
$order = wc_get_order( $wp->query_vars['view-order'] );
$title = ( $order ) ? sprintf( __( 'Order %s', 'woocommerce' ), _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ) : '';
$title = ( $order ) ? sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ) : '';
break;
case 'edit-account' :
$title = __( 'Edit Account Details', 'woocommerce' );
@ -294,8 +294,8 @@ class WC_Query {
$this->product_query( $q );
if ( is_search() ) {
add_filter( 'posts_where', array( $this, 'search_post_excerpt' ) );
add_filter( 'wp', array( $this, 'remove_posts_where' ) );
add_filter( 'posts_where', array( $this, 'search_post_excerpt' ) );
add_filter( 'wp', array( $this, 'remove_posts_where' ) );
}
// We're on a shop page so queue the woocommerce_get_products_in_view function
@ -317,11 +317,11 @@ class WC_Query {
// If this is not a WC Query, do not modify the query
if ( empty( $wp_the_query->query_vars['wc_query'] ) || empty( $wp_the_query->query_vars['s'] ) )
return $where;
return $where;
$where = preg_replace(
"/post_title\s+LIKE\s*(\'\%[^\%]+\%\')/",
"post_title LIKE $1) OR (post_excerpt LIKE $1", $where );
"/post_title\s+LIKE\s*(\'\%[^\%]+\%\')/",
"post_title LIKE $1) OR (post_excerpt LIKE $1", $where );
return $where;
}
@ -378,16 +378,16 @@ class WC_Query {
// Abort if we're not on a post type archive/product taxonomy
if ( ! $query->is_post_type_archive( 'product' ) && ! $query->is_tax( get_object_taxonomies( 'product' ) ) )
return $posts;
return $posts;
$filtered_posts = array();
$queried_post_ids = array();
foreach ( $posts as $post ) {
if ( in_array( $post->ID, $this->post__in ) ) {
$filtered_posts[] = $post;
$queried_post_ids[] = $post->ID;
}
if ( in_array( $post->ID, $this->post__in ) ) {
$filtered_posts[] = $post;
$queried_post_ids[] = $post->ID;
}
}
$query->posts = $filtered_posts;
@ -398,9 +398,9 @@ class WC_Query {
$this->filtered_product_ids = $queried_post_ids;
if ( sizeof( $this->layered_nav_post__in ) > 0 ) {
$this->layered_nav_product_ids = array_intersect( $this->unfiltered_product_ids, $this->layered_nav_post__in );
$this->layered_nav_product_ids = array_intersect( $this->unfiltered_product_ids, $this->layered_nav_post__in );
} else {
$this->layered_nav_product_ids = $this->unfiltered_product_ids;
$this->layered_nav_product_ids = $this->unfiltered_product_ids;
}
return $filtered_posts;
@ -498,8 +498,8 @@ class WC_Query {
if ( false === ( $unfiltered_product_ids = get_transient( $transient_name ) ) ) {
// Get all visible posts, regardless of filters
$unfiltered_product_ids = get_posts(
// Get all visible posts, regardless of filters
$unfiltered_product_ids = get_posts(
array_merge(
$current_wp_query,
array(
@ -672,9 +672,9 @@ class WC_Query {
$in = array( 'visible', 'catalog' );
$meta_query = array(
'key' => '_visibility',
'value' => $in,
'compare' => $compare
'key' => '_visibility',
'value' => $in,
'compare' => $compare
);
return $meta_query;
@ -691,10 +691,10 @@ class WC_Query {
$meta_query = array();
if ( get_option( 'woocommerce_hide_out_of_stock_items' ) == 'yes' ) {
$meta_query = array(
'key' => '_stock_status',
'key' => '_stock_status',
'value' => $status,
'compare' => '='
);
);
}
return $meta_query;
}
@ -719,21 +719,21 @@ class WC_Query {
$name = 'filter_' . $attribute;
$query_type_name = 'query_type_' . $attribute;
if ( ! empty( $_GET[ $name ] ) && taxonomy_exists( $taxonomy ) ) {
if ( ! empty( $_GET[ $name ] ) && taxonomy_exists( $taxonomy ) ) {
$_chosen_attributes[ $taxonomy ]['terms'] = explode( ',', $_GET[ $name ] );
$_chosen_attributes[ $taxonomy ]['terms'] = explode( ',', $_GET[ $name ] );
if ( empty( $_GET[ $query_type_name ] ) || ! in_array( strtolower( $_GET[ $query_type_name ] ), array( 'and', 'or' ) ) )
$_chosen_attributes[ $taxonomy ]['query_type'] = apply_filters( 'woocommerce_layered_nav_default_query_type', 'and' );
else
$_chosen_attributes[ $taxonomy ]['query_type'] = strtolower( $_GET[ $query_type_name ] );
if ( empty( $_GET[ $query_type_name ] ) || ! in_array( strtolower( $_GET[ $query_type_name ] ), array( 'and', 'or' ) ) )
$_chosen_attributes[ $taxonomy ]['query_type'] = apply_filters( 'woocommerce_layered_nav_default_query_type', 'and' );
else
$_chosen_attributes[ $taxonomy ]['query_type'] = strtolower( $_GET[ $query_type_name ] );
}
}
}
}
add_filter('loop_shop_post_in', array( $this, 'layered_nav_query' ) );
}
add_filter('loop_shop_post_in', array( $this, 'layered_nav_query' ) );
}
}
/**
@ -857,45 +857,80 @@ class WC_Query {
* @return array
*/
public function price_filter( $filtered_posts = array() ) {
global $wpdb;
global $wpdb;
if ( isset( $_GET['max_price'] ) || isset( $_GET['min_price'] ) ) {
if ( isset( $_GET['max_price'] ) || isset( $_GET['min_price'] ) ) {
$matched_products = array();
$min = isset( $_GET['min_price'] ) ? floatval( $_GET['min_price'] ) : 0;
$max = isset( $_GET['max_price'] ) ? floatval( $_GET['max_price'] ) : 9999999999;
$matched_products_query = apply_filters( 'woocommerce_price_filter_results', $wpdb->get_results( $wpdb->prepare( '
SELECT DISTINCT ID, post_parent, post_type FROM %1$s
INNER JOIN %2$s ON ID = post_id
WHERE post_type IN ( "product", "product_variation" )
AND post_status = "publish"
AND meta_key IN ("' . implode( '","', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) . '")
AND meta_value BETWEEN %3$d AND %4$d
', $wpdb->posts, $wpdb->postmeta, $min, $max ), OBJECT_K ), $min, $max );
// If displaying prices in the shop including taxes, but prices don't include taxes..
if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
if ( $matched_products_query ) {
foreach ( $matched_products_query as $product ) {
if ( $product->post_type == 'product' ) {
$matched_products[] = $product->ID;
}
if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) ) {
$matched_products[] = $product->post_parent;
}
}
}
foreach ( $tax_classes as $tax_class ) {
$tax_rates = WC_Tax::get_rates( $tax_class );
$min_class = $min - WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $min, $tax_rates ) );
$max_class = $max - WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $max, $tax_rates ) );
// Filter the id's
if ( 0 === sizeof( $filtered_posts ) ) {
$matched_products_query = apply_filters( 'woocommerce_price_filter_results', $wpdb->get_results( $wpdb->prepare( '
SELECT DISTINCT ID, post_parent, post_type FROM %1$s
INNER JOIN %2$s pm1 ON ID = pm1.post_id
INNER JOIN %2$s pm2 ON ID = pm2.post_id
WHERE post_type IN ( "product", "product_variation" )
AND post_status = "publish"
AND pm1.meta_key IN ("' . implode( '","', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) . '")
AND pm1.meta_value BETWEEN %3$d AND %4$d
AND pm2.meta_key = "_tax_class"
AND pm2.meta_value = "%5$s"
', $wpdb->posts, $wpdb->postmeta, $min_class, $max_class, sanitize_title( $tax_class ) ), OBJECT_K ), $min_class, $max_class );
if ( $matched_products_query ) {
foreach ( $matched_products_query as $product ) {
if ( $product->post_type == 'product' ) {
$matched_products[] = $product->ID;
}
if ( $product->post_parent > 0 ) {
$matched_products[] = $product->post_parent;
}
}
}
}
} else {
$matched_products_query = apply_filters( 'woocommerce_price_filter_results', $wpdb->get_results( $wpdb->prepare( '
SELECT DISTINCT ID, post_parent, post_type FROM %1$s
INNER JOIN %2$s pm1 ON ID = post_id
WHERE post_type IN ( "product", "product_variation" )
AND post_status = "publish"
AND pm1.meta_key IN ("' . implode( '","', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) . '")
AND pm1.meta_value BETWEEN %3$d AND %4$d
', $wpdb->posts, $wpdb->postmeta, $min, $max, $tax_class ), OBJECT_K ), $min, $max );
if ( $matched_products_query ) {
foreach ( $matched_products_query as $product ) {
if ( $product->post_type == 'product' ) {
$matched_products[] = $product->ID;
}
if ( $product->post_parent > 0 ) {
$matched_products[] = $product->post_parent;
}
}
}
}
$matched_products = array_unique( $matched_products );
// Filter the id's
if ( 0 === sizeof( $filtered_posts ) ) {
$filtered_posts = $matched_products;
} else {
} else {
$filtered_posts = array_intersect( $filtered_posts, $matched_products );
}
$filtered_posts[] = 0;
}
}
$filtered_posts[] = 0;
}
return (array) $filtered_posts;
return (array) $filtered_posts;
}
}

View File

@ -104,7 +104,7 @@ class WC_Tax {
* @param array $rates
* @return array
*/
private static function calc_inclusive_tax( $price, $rates ) {
public static function calc_inclusive_tax( $price, $rates ) {
$taxes = array();
$regular_tax_rates = $compound_tax_rates = 0;
@ -148,7 +148,7 @@ class WC_Tax {
* @param array $rates
* @return array
*/
private static function calc_exclusive_tax( $price, $rates ) {
public static function calc_exclusive_tax( $price, $rates ) {
$taxes = array();
if ( $rates ) {

View File

@ -2,11 +2,11 @@
/**
* Contains Validation functions
*
* @class WC_Validation
* @version 2.1.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @class WC_Validation
* @version 2.4.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
*/
class WC_Validation {
@ -27,8 +27,9 @@ class WC_Validation {
* @return bool
*/
public static function is_phone( $phone ) {
if ( strlen( trim( preg_replace( '/[\s\#0-9_\-\+\(\)]/', '', $phone ) ) ) > 0 )
if ( 0 < strlen( trim( preg_replace( '/[\s\#0-9_\-\+\(\)]/', '', $phone ) ) ) ) {
return false;
}
return true;
}
@ -41,50 +42,53 @@ class WC_Validation {
* @return bool
*/
public static function is_postcode( $postcode, $country ) {
if ( strlen( trim( preg_replace( '/[\s\-A-Za-z0-9]/', '', $postcode ) ) ) > 0 )
if ( strlen( trim( preg_replace( '/[\s\-A-Za-z0-9]/', '', $postcode ) ) ) > 0 ) {
return false;
switch ( $country ) {
case "GB" :
return self::is_GB_postcode( $postcode );
case "US" :
if ( preg_match( "/^([0-9]{5})(-[0-9]{4})?$/i", $postcode ) )
return true;
else
return false;
case "CH" :
if ( preg_match( "/^([0-9]{4})$/i", $postcode ) )
return true;
else
return false;
case "BR" :
if ( preg_match( "/^([0-9]{5,5})([-])?([0-9]{3,3})$/", $postcode ) )
return true;
else
return false;
}
return true;
switch ( $country ) {
case 'BR' :
$valid = (bool) preg_match( '/^([0-9]{5})([-])?([0-9]{3})$/', $postcode );
break;
case 'CH' :
$valid = (bool) preg_match( '/^([0-9]{4})$/i', $postcode );
break;
case 'GB' :
$valid = self::is_GB_postcode( $postcode );
break;
case 'PT' :
$valid = (bool) preg_match( '/^([0-9]{4})([-])([0-9]{3})$/', $postcode );
break;
case 'US' :
$valid = (bool) preg_match( '/^([0-9]{5})(-[0-9]{4})?$/i', $postcode );
break;
default :
$valid = true;
break;
}
return apply_filters( 'woocommerce_validate_postcode', $valid, $postcode, $country );
}
/**
* is_GB_postcode function.
* Check if is a GB postcode.
*
* @author John Gardner
* @param string $to_check A postcode
* @param string $to_check A postcode
* @return bool
*/
public static function is_GB_postcode( $to_check ) {
// Permitted letters depend upon their position in the postcode.
// http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation
$alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1
$alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2
$alpha3 = "[abcdefghjkpstuw]"; // Character 3 == ABCDEFGHJKPSTUW
$alpha4 = "[abehmnprvwxy]"; // Character 4 == ABEHMNPRVWXY
$alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5 != CIKMOV
$alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1
$alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2
$alpha3 = "[abcdefghjkpstuw]"; // Character 3 == ABCDEFGHJKPSTUW
$alpha4 = "[abehmnprvwxy]"; // Character 4 == ABEHMNPRVWXY
$alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5 != CIKMOV
$pcexp = array();
$pcexp = array();
// Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
$pcexp[0] = '/^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$/';

View File

@ -561,6 +561,7 @@ class WC_Webhook {
'order.updated' => array(
'woocommerce_process_shop_order_meta',
'woocommerce_api_edit_order',
'woocommerce_order_edit_status',
),
'order.deleted' => array(
'wp_trash_post',

View File

@ -244,7 +244,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
$this->send_ipn_email_notification(
sprintf( __( 'Payment for order #%s refunded/reversed', 'woocommerce' ), $order->get_order_number() ),
sprintf( __( 'Order %s has been marked as refunded - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
sprintf( __( 'Order #%s has been marked as refunded - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
);
}
}
@ -258,7 +258,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
$this->send_ipn_email_notification(
sprintf( __( 'Payment for order #%s reversed', 'woocommerce' ), $order->get_order_number() ),
sprintf( __( 'Order %s has been marked on-hold due to a reversal - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), wc_clean( $posted['reason_code'] ) )
sprintf( __( 'Order #%s has been marked on-hold due to a reversal - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), wc_clean( $posted['reason_code'] ) )
);
}

View File

@ -76,7 +76,7 @@ class WC_Gateway_Paypal_Request {
'paymentaction' => $this->gateway->get_option( 'paymentaction' ),
'bn' => 'WooThemes_Cart',
'invoice' => $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(),
'custom' => serialize( array( $order->id, $order->order_key ) ),
'custom' => json_encode( array( 'order_id' => $order->id, 'order_key' => $order->order_key ) ),
'notify_url' => $this->notify_url,
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,

View File

@ -15,32 +15,37 @@ abstract class WC_Gateway_Paypal_Response {
/**
* Get the order from the PayPal 'Custom' variable
*
* @param string $custom
* @param string $raw_custom JSON Data passed back by PayPal
* @return bool|WC_Order object
*/
protected function get_paypal_order( $custom ) {
$custom = maybe_unserialize( $custom );
protected function get_paypal_order( $raw_custom ) {
// We have the data in the correct format, so get the order
if ( ( $custom = json_decode( $raw_custom ) ) && is_object( $custom ) ) {
$order_id = $custom->order_id;
$order_key = $custom->order_key;
if ( is_array( $custom ) ) {
// Fallback to serialized data if safe. This is @deprecated in 2.3.11
} elseif ( preg_match( '/^a:2:{/', $raw_custom ) && ! preg_match( '/[CO]:\+?[0-9]+:"/', $raw_custom ) && ( $custom = maybe_unserialize( $raw_custom ) ) ) {
$order_id = $custom[0];
$order_key = $custom[1];
list( $order_id, $order_key ) = $custom;
if ( ! $order = wc_get_order( $order_id ) ) {
// We have an invalid $order_id, probably because invoice_prefix has changed
$order_id = wc_get_order_id_by_order_key( $order_key );
$order = wc_get_order( $order_id );
}
if ( ! $order || $order->order_key !== $order_key ) {
WC_Gateway_Paypal::log( 'Error: Order Keys do not match.' );
return false;
}
} elseif ( ! $order = apply_filters( 'woocommerce_get_paypal_order', false, $custom ) ) {
// Nothing was found
} else {
WC_Gateway_Paypal::log( 'Error: Order ID and key were not found in "custom".' );
return false;
}
if ( ! $order = wc_get_order( $order_id ) ) {
// We have an invalid $order_id, probably because invoice_prefix has changed
$order_id = wc_get_order_id_by_order_key( $order_key );
$order = wc_get_order( $order_id );
}
if ( ! $order || $order->order_key !== $order_key ) {
WC_Gateway_Paypal::log( 'Error: Order Keys do not match.' );
return false;
}
return $order;
}

View File

@ -29,7 +29,7 @@ foreach ( $api_users as $_user ) {
$apps_keys[] = array(
'user_id' => $user->ID,
'permission' => $user->woocommerce_api_key_permissions,
'consumer_key' => $user->woocommerce_api_consumer_key,
'consumer_key' => wc_api_hash( $user->woocommerce_api_consumer_key ),
'consumer_secret' => $user->woocommerce_api_consumer_secret
);
}
@ -58,6 +58,18 @@ if ( ! empty( $apps_keys ) ) {
}
}
// Make sure order.update webhooks get the woocommerce_order_edit_status hook
$order_update_webhooks = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'shop_webhook',
'meta_key' => '_topic',
'meta_value' => 'order.updated'
) );
foreach ( $order_update_webhooks as $order_update_webhook ) {
$webhook = new WC_Webhook( $order_update_webhook->ID );
$webhook->set_topic( 'order.updated' );
}
// Update fully refunded orders to ensure they have a refund line item so reports add up
$refunded_orders = get_posts( array(
'posts_per_page' => -1,

View File

@ -289,7 +289,7 @@ if ( ! function_exists( 'wc_tax_enabled' ) ) {
* @return bool
*/
function wc_tax_enabled() {
return get_option( 'woocommerce_calc_taxes' ) === 'yes';
return apply_filters( 'wc_tax_enabled', get_option( 'woocommerce_calc_taxes' ) === 'yes' );
}
}

View File

@ -803,3 +803,28 @@ if ( ! function_exists( 'hash_equals' ) ) :
return $result === 0;
}
endif;
/**
* Generate a rand hash
*
* @since 2.4.0
* @return string
*/
function wc_rand_hash() {
if ( function_exists( 'openssl_random_pseudo_bytes' ) ) {
return bin2hex( openssl_random_pseudo_bytes( 20 ) );
} else {
return sha1( wp_rand() );
}
}
/**
* WC API - Hash
*
* @since 2.4.0
* @param string $data
* @return string
*/
function wc_api_hash( $data ) {
return hash_hmac( 'sha256', $data, 'wc-api' );
}

View File

@ -86,7 +86,7 @@ function wc_delete_product_transients( $post_id = 0 ) {
// Transients that include an ID
$post_transient_names = array(
'wc_product_children_ids_',
'wc_product_children',
'wc_product_total_stock_'
);

View File

@ -292,8 +292,8 @@ function wc_product_post_class( $classes, $class = '', $post_id = '' ) {
if ( $product->is_purchasable() ) {
$classes[] = 'purchasable';
}
if ( isset( $product->product_type ) ) {
$classes[] = "product-type-" . $product->product_type;
if ( $product->get_type() ) {
$classes[] = "product-type-" . $product->get_type();
}
// add category slugs

View File

@ -88,7 +88,7 @@ function wc_get_product_terms( $product_id, $taxonomy, $args = array() ) {
$terms = wp_get_post_terms( $product_id, $taxonomy, $args );
}
return $terms;
return apply_filters( 'woocommerce_get_product_terms' , $terms, $product_id, $taxonomy, $args );
}

View File

@ -66,7 +66,12 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
foreach ( $_chosen_attributes as $taxonomy => $data ) {
foreach ( $data['terms'] as $term_id ) {
$term = get_term( $term_id, $taxonomy );
$term = get_term( $term_id, $taxonomy );
if ( ! isset( $term->name ) ) {
continue;
}
$taxonomy_filter = str_replace( 'pa_', '', $taxonomy );
$current_filter = ! empty( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' . $taxonomy_filter ] : '';
$new_filter = array_map( 'absint', explode( ',', $current_filter ) );

View File

@ -229,19 +229,16 @@ class WC_Widget_Layered_Nav extends WC_Widget {
}
echo '<option value="' . esc_attr( $term->term_id ) . '" ' . selected( isset( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' .$taxonomy_filter ] : '' , $term->term_id, false ) . '>' . esc_html( $term->name ) . '</option>';
echo '<option value="' . esc_attr( $term->term_id ) . '" ' . selected( isset( $_GET[ 'filter_' . $taxonomy_filter ] ) ? $_GET[ 'filter_' . $taxonomy_filter ] : '' , $term->term_id, false ) . '>' . esc_html( $term->name ) . '</option>';
}
echo '</select>';
wc_enqueue_js( "
jQuery('.dropdown_layered_nav_$taxonomy_filter').change(function(){
location.href = '" . esc_url_raw( preg_replace( '%\/page/[0-9]+%', '', add_query_arg( 'filtering', '1', remove_query_arg( array( 'page', 'filter_' . $taxonomy_filter ) ) ) ) ) . "&filter_$taxonomy_filter=' + jQuery(this).val();
jQuery( '.dropdown_layered_nav_$taxonomy_filter' ).change( function() {
var term_id = parseInt( jQuery( this ).val(), 10 );
location.href = '" . str_replace( array( '%\/page/[0-9]+%', '&amp;', '%2C' ), array( '', '&', ',' ), esc_js( add_query_arg( 'filtering', '1', remove_query_arg( array( 'page', 'filter_' . $taxonomy_filter ) ) ) ) ) . "&filter_$taxonomy_filter=' + ( isNaN( term_id ) ? '' : term_id );
});
" );
}

View File

@ -161,6 +161,24 @@ class WC_Widget_Price_Filter extends WC_Widget {
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) );
}
if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
$min = 0;
foreach ( $tax_classes as $tax_class ) {
$tax_rates = WC_Tax::get_rates( $tax_class );
$class_min = $min + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $min, $tax_rates ) );
$class_max = $max + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max, $tax_rates ) );
if ( $min === 0 || $class_min < $min ) {
$min = $class_min;
}
if ( $class_max > $max ) {
$max = $class_max;
}
}
}
echo '<form method="get" action="' . esc_url( $form_action ) . '">
<div class="price_slider_wrapper">
<div class="price_slider" style="display:none;"></div>

View File

@ -32,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) {
$no_gateways_message = __( 'Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' );
}
echo '<p>' . apply_filters( 'woocommerce_no_available_payment_methods_message', $no_gateways_message ) . '</p>';
echo '<li>' . apply_filters( 'woocommerce_no_available_payment_methods_message', $no_gateways_message ) . '</li>';
}
?>
</ul>

View File

@ -56,7 +56,7 @@ foreach ( $items as $item_id => $item ) :
$prefix = __( 'Download', 'woocommerce' );
}
echo '<br/><small>' . $prefix . ': <a href="' . esc_url( $file['download_url'] ) . '" target="_blank">' . esc_html( $file['name'] ) . '</a></small>';
echo '<br/><small>' . $prefix . ': <a href="' . esc_url( $file['download_url'] ) . '" target="_blank">' . esc_html( $file['name'] ) . '</a></small>' . "\n";
}
}

View File

@ -46,7 +46,7 @@ if ( $customer_orders ) : ?>
?><tr class="order">
<td class="order-number" data-title="<?php _e( 'Order Number', 'woocommerce' ); ?>">
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
#<?php echo $order->get_order_number(); ?>
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a>
</td>
<td class="order-date" data-title="<?php _e( 'Date', 'woocommerce' ); ?>">

View File

@ -77,9 +77,9 @@ class WC_Helper_Product {
// Price related meta
update_post_meta( $product_id, '_price', '10' );
update_post_meta( $product_id, '_min_variation_price', '10' );
update_post_meta( $product_id, '_max_variation_price', '10' );
update_post_meta( $product_id, '_max_variation_price', '15' );
update_post_meta( $product_id, '_min_variation_regular_price', '10' );
update_post_meta( $product_id, '_max_variation_regular_price', '10' );
update_post_meta( $product_id, '_max_variation_regular_price', '15' );
// General meta
update_post_meta( $product_id, '_sku', 'DUMMY SKU' );
@ -135,6 +135,31 @@ class WC_Helper_Product {
// Add the variation meta to the main product
update_post_meta( $product_id, '_min_price_variation_id', $variation_id );
// Create the variation
$variation_id = wp_insert_post( array(
'post_title' => 'Variation #' . ( $product_id + 2 ) . ' of Dummy Product',
'post_type' => 'product_variation',
'post_parent' => $product_id,
'post_status' => 'publish'
) );
// Price related meta
update_post_meta( $variation_id, '_price', '15' );
update_post_meta( $variation_id, '_regular_price', '15' );
// General meta
update_post_meta( $variation_id, '_sku', 'DUMMY SKU VARIABLE SMALL' );
update_post_meta( $variation_id, '_manage_stock', 'no' );
update_post_meta( $variation_id, '_downloadable', 'no' );
update_post_meta( $variation_id, '_virtual', 'taxable' );
update_post_meta( $variation_id, '_stock_status', 'instock' );
// Attribute meta
update_post_meta( $variation_id, 'attribute_pa_size', 'large' );
// Add the variation meta to the main product
update_post_meta( $product_id, '_max_price_variation_id', $variation_id );
return new WC_Product_Variable( $product_id );

View File

@ -0,0 +1,30 @@
<?php
namespace WooCommerce\Tests\API;
/**
* Class Functions
* @package WooCommerce\Tests\API
* @since 2.4
*/
class Orders extends \WC_API_Unit_Test_Case {
/**
* Test test_wc_api_order_get_variation_id_returns_correct_id
*
* @since 2.4
*/
public function test_wc_api_order_get_variation_id_returns_correct_id() {
parent::setUp();
$product = \WC_Helper_Product::create_variation_product();
$orders_api = WC()->api->WC_API_Orders;
$variation_id = $orders_api->get_variation_id( $product, array( 'size' => 'small' ) );
$this->assertSame( ( $product->id + 1 ), $variation_id );
$variation_id = $orders_api->get_variation_id( $product, array( 'size' => 'large' ) );
$this->assertSame( ( $product->id + 2 ), $variation_id );
}
}

View File

@ -6,8 +6,8 @@
* Version: 2.4.0-dev
* Author: WooThemes
* Author URI: http://woothemes.com
* Requires at least: 4.0
* Tested up to: 4.1
* Requires at least: 4.1
* Tested up to: 4.2
*
* Text Domain: woocommerce
* Domain Path: /i18n/languages/