Skip to content
Permalink
Browse files

Fix: variation stock adjustment after sale

  • Loading branch information...
kilbot committed Aug 19, 2015
1 parent 837b918 commit 26978fd0e74cfb9cf28ef2bb4bc5222820a77d38
Showing with 188 additions and 175 deletions.
  1. +1 −1 Gruntfile.js
  2. +2 −1 assets/js/src/entities/orders/model.js
  3. +14 −0 assets/js/src/entities/products/model.js
  4. +13 −14 assets/js/src/lib/config/dual-model.js
  5. +1 −1 assets/js/src/lib/config/model.js
  6. +4 −4 includes/api/class-wc-pos-orders.php
  7. +1 −1 languages/js/af_ZA.js
  8. +1 −1 languages/js/ar.js
  9. +1 −1 languages/js/ar_MA.js
  10. +1 −1 languages/js/ar_SA.js
  11. +1 −1 languages/js/az.js
  12. +1 −1 languages/js/be.js
  13. +1 −1 languages/js/bg_BG.js
  14. +1 −1 languages/js/bn.js
  15. +1 −1 languages/js/bo_CN.js
  16. +1 −1 languages/js/br_FR.js
  17. +1 −1 languages/js/bs.js
  18. +1 −1 languages/js/ca.js
  19. +0 −1 languages/js/ca_ES.js
  20. +1 −1 languages/js/cs_CZ.js
  21. +1 −1 languages/js/cy_GB.js
  22. +1 −1 languages/js/da_DK.js
  23. +1 −1 languages/js/de.js
  24. +1 −1 languages/js/de_AT.js
  25. +1 −1 languages/js/el_GR.js
  26. +1 −1 languages/js/en_AU.js
  27. +1 −1 languages/js/en_CA.js
  28. +1 −1 languages/js/en_GB.js
  29. +1 −1 languages/js/es.js
  30. +1 −1 languages/js/et_EE.js
  31. +1 −1 languages/js/eu_ES.js
  32. +1 −1 languages/js/fa_IR.js
  33. +1 −1 languages/js/fi_FI.js
  34. +1 −1 languages/js/fr.js
  35. +1 −1 languages/js/fr_CA.js
  36. +1 −1 languages/js/gl_ES.js
  37. +1 −1 languages/js/he_IL.js
  38. +1 −1 languages/js/hi_IN.js
  39. +1 −1 languages/js/hr.js
  40. +1 −1 languages/js/hu_HU.js
  41. +1 −1 languages/js/hy_AM.js
  42. +1 −1 languages/js/id_ID.js
  43. +1 −1 languages/js/is_IS.js
  44. +1 −1 languages/js/it.js
  45. +1 −1 languages/js/ja_JP.js
  46. +1 −1 languages/js/ka_GE.js
  47. +1 −1 languages/js/km_KH.js
  48. +1 −1 languages/js/ko_KR.js
  49. +1 −1 languages/js/lt_LT.js
  50. +1 −1 languages/js/lv_LV.js
  51. +1 −1 languages/js/mk_MK.js
  52. +1 −1 languages/js/ml_IN.js
  53. +1 −1 languages/js/mr_IN.js
  54. +1 −1 languages/js/ms_MY.js
  55. +1 −1 languages/js/nb_NO.js
  56. +1 −1 languages/js/ne_NP.js
  57. +1 −1 languages/js/nl.js
  58. +1 −1 languages/js/pl_PL.js
  59. +1 −1 languages/js/pt_BR.js
  60. +1 −1 languages/js/pt_PT.js
  61. +1 −1 languages/js/ro_RO.js
  62. +1 −1 languages/js/ru_RU.js
  63. +1 −1 languages/js/sk_SK.js
  64. +1 −1 languages/js/sl_SI.js
  65. +1 −1 languages/js/sq_AL.js
  66. +1 −1 languages/js/sr.js
  67. +1 −1 languages/js/sr_Cyrl.js
  68. +1 −1 languages/js/sv.js
  69. +1 −1 languages/js/ta_IN.js
  70. +1 −1 languages/js/th_TH.js
  71. +1 −1 languages/js/tr_TR.js
  72. +1 −1 languages/js/tzm.js
  73. +1 −1 languages/js/uk_UA.js
  74. +1 −1 languages/js/uz.js
  75. +1 −1 languages/js/vi_VN.js
  76. +1 −1 languages/js/zh_CN.js
  77. +1 −1 languages/js/zh_TW.js
  78. +41 −25 languages/woocommerce-pos-admin.pot
  79. +41 −57 languages/woocommerce-pos.pot
  80. +1 −1 readme.txt
@@ -23,7 +23,7 @@ module.exports = function(grunt) {
}

grunt.initConfig({
//pkg: grunt.file.readJSON('package.json'),
pkg: grunt.file.readJSON('package.json'),

// file paths
app: {
@@ -216,7 +216,8 @@ var Model = DualModel.extend({
return self.processGateway();
})
.then(function(){
return self.remoteSync();
var method = self.get('id') ? 'update' : 'create';
return self.remoteSync(method);
})
.then(function(array){
var model = array[0];
@@ -18,6 +18,20 @@ module.exports = DualModel.extend({
stock_quantity: 'number'
},

initialize: function(){
this.on({
'change:updated_at': this.onUpdate
});
},

onUpdate: function(){
// update stock
if( this.get('type') === 'variable' ){
var variations = this.getVariations().superset();
variations.set( this.get('variations') );
}
},

/**
* Helper functions for variation prices
*/
@@ -1,7 +1,7 @@
var DeepModel = require('./deep-model');
var POS = require('lib/utilities/global');
var _ = require('lodash');
//var debug = require('debug')('dualModel');
var debug = require('debug')('dualModel');

module.exports = POS.DualModel = DeepModel.extend({
idAttribute: 'local_id',
@@ -72,10 +72,8 @@ module.exports = POS.DualModel = DeepModel.extend({
model = model || this;
options = options || {};
options.remote = true;
method = method || model.getMethod();

//if(method !== 'read'){
// method = model.getMethod(method);
//}
return DeepModel.prototype.sync.call(this, method, model, options)
.then(function(resp){
if(resp){
@@ -94,16 +92,17 @@ module.exports = POS.DualModel = DeepModel.extend({
}
},

//getMethod: function(method){
// var status = this.get('status');
// var remoteMethod = _.findKey(this.states, function(state) {
// return state === status;
// });
// if(remoteMethod){
// return remoteMethod;
// }
// return method;
//},
getMethod: function(){
var status = this.get('status');
var remoteMethod = _.findKey(this.states, function(state) {
return state === status;
});
if(remoteMethod){
return remoteMethod;
} else {
debug('No method given for remote sync');
}
},

merge: function(resp){
// todo: merge
@@ -17,7 +17,7 @@ module.exports = POS.Model = bb.Model.extend({
},

parse: function (resp){
var data = resp[this.name] || resp;
var data = resp && resp[this.name] ? resp[this.name] : resp;
if( ! data ){
return;
}
@@ -488,11 +488,11 @@ private function payment_redirect($gateway_id, $order_id, $response){
// compare url fragments
$success_url = wc_get_endpoint_url( 'order-received', $order_id, get_permalink( wc_get_page_id( 'checkout' ) ) );
$success_frag = parse_url( $success_url );
$redirect_frag = parse_url( $response['redirect'] );
$success = wp_parse_args( parse_url( $success_url ), array( 'host' => '', 'path' => '' ));
$redirect = wp_parse_args( parse_url( $response['redirect'] ), array( 'host' => '', 'path' => '' ));
$offsite = $success_frag['host'] !== $redirect_frag['host'];
$reload = !$offsite && $success_frag['path'] !== $redirect_frag['path'] && $response['messages'] == '';
$offsite = $success['host'] !== $redirect['host'];
$reload = !$offsite && $success['path'] !== $redirect['path'] && $response['messages'] == '';
if($offsite || $reload){
update_post_meta( $order_id, '_pos_payment_redirect', $response['redirect'] );

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

0 comments on commit 26978fd

Please sign in to comment.
You can’t perform that action at this time.