Skip to content

Instantly share code, notes, and snippets.

@yk2kus
Created May 6, 2015 17:46
Show Gist options
  • Save yk2kus/899fe6bc649fd66f7828 to your computer and use it in GitHub Desktop.
Save yk2kus/899fe6bc649fd66f7828 to your computer and use it in GitHub Desktop.
module.Order = Backbone.Model.extend({
addProduct: function(product, options){
options = options || {};
var attr = JSON.parse(JSON.stringify(product));
attr.pos = this.pos;
attr.order = this;
var line = new module.Orderline({}, {pos: this.pos, order: this, product: product});
console.log("add products................",product)
if(options.quantity !== undefined){
line.set_quantity(options.quantity);
}
if(options.price !== undefined){
line.set_unit_price(options.price);
}
if(options.discount !== undefined){
line.set_discount(options.discount);
}
var last_orderline = this.getLastOrderline();
if( last_orderline && last_orderline.can_be_merged_with(line) && options.merge !== false){
last_orderline.merge(line);
}else{
this.get('orderLines').add(line);
}
this.selectLine(this.getLastOrderline());
},
})
module.Order = module.Order.extend({
addProduct: function(product, options){
this._super(product, options);
console.log("added product.................",product);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment