Skip to content
Permalink
Browse files

Fix: cart totals going to zero with new fee or shipping line item

  • Loading branch information...
kilbot committed Aug 26, 2015
1 parent d93942b commit 35f547cf40919736ff769702043489ff1698ec30
@@ -18,6 +18,7 @@ module.exports = Model.extend({
'tax_class' : ''
},

/* jshint -W074 */
initialize: function() {

// attach tax settings
@@ -41,9 +42,11 @@ module.exports = Model.extend({

// set item price on init, this wil kick off updateLineTotals
if( this.get('item_price') === undefined ) {
this.set({ 'item_price': parseFloat( this.get('price') ) });
var price = parseFloat( this.get('price') );
this.set({ 'item_price': _.isNaN(price) ? 0 : price });
}
},
/* jshint +W074 */

/* jshint -W071, -W074 */
/* todo: too many statements, too complex */
@@ -7,7 +7,10 @@ var _ = require('lodash');
var parse = {
'float': parseFloat,
'int': parseInt,
'number': Number
'number': function(num){
num = Number(num);
return _.isNaN(num) ? 0 : num;
}
};

module.exports = POS.Model = bb.Model.extend({
@@ -77,6 +77,9 @@ Bugs can be reported on the [WooCommerce POS GitHub repository](https://github.c

== Changelog ==

= 0.4.4 =
* Fix: cart totals going to zero with new fee or shipping line item - commit []()

= 0.4.3 =
* Fix: barcode scanning bug introduced in version 0.4.2 - commit [8a608c8](https://github.com/kilbot/WooCommerce-POS/commit/8a608c8124d77cd3499af55e08651752287261bc)

@@ -437,6 +437,36 @@ describe('entities/cart/model.js', function () {

});

describe('fee line items', function () {

beforeEach(function () {

var Model = require('entities/cart/model').extend({
url: '?',
collection: {tax_rates: {}}
});
this.model = new Model({
type: 'fee'
});

});

it('should be in a valid state', function(){
this.model.should.be.ok;
});

it('should init with default values', function(){
this.model.get('item_subtotal').should.eql(0);
this.model.get('item_subtotal_tax').should.eql(0);
this.model.get('item_tax').should.eql(0);
this.model.get('subtotal').should.eql(0);
this.model.get('subtotal_tax').should.eql(0);
this.model.get('total').should.eql(0);
this.model.get('total_tax').should.eql(0);
});

});

describe('shipping line items', function () {

beforeEach(function () {
@@ -451,6 +481,20 @@ describe('entities/cart/model.js', function () {

});

it('should be in a valid state', function(){
this.model.should.be.ok;
});

it('should init with default values', function(){
this.model.get('item_subtotal').should.eql(0);
this.model.get('item_subtotal_tax').should.eql(0);
this.model.get('item_tax').should.eql(0);
this.model.get('subtotal').should.eql(0);
this.model.get('subtotal_tax').should.eql(0);
this.model.get('total').should.eql(0);
this.model.get('total_tax').should.eql(0);
});

describe('shipping line using GB dummy tax', function () {

beforeEach(function () {

0 comments on commit 35f547c

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