3
votes

I'm updating the update_payment_summary function in the Point_Of_Sale, this function is part of the PaymentScreenWidget. Now I'd like to retrieve the products from the orderlines.

I tried with

var order = this.pos.get('selectedOrder');
var orderlines = order.get('orderLines').models;

But when I print orderlines I get [object Object]

Any ideas how I can get the product object of every orderline?

2

2 Answers

2
votes

use the get_orderlines() function to get OrderLines from particular Order.

var order = this.pos.get_order();
var products = _.map(order.get_orderlines(), function (line) {return line.product; });
console.log(products);

here i user Underscore.js for create a list of products.

you can iterate loop with products list like,

for(var i =0; i < products.length; i++)
    console.log(products[i].id);
2
votes

Yes there is a reason why it shows object.

OrderlineCollection definition.

module.OrderlineCollection = Backbone.Collection.extend({
        model: module.Orderline,
});

Orderline definition in Order Model.

orderLines:     new module.OrderlineCollection()

So if you observe above code it shows that orderline is an object of OrderlineCollection model and while you get orderlines from order model it will gives you an object of OrderlineCollection.

In order to identify what's there inside object you can iterate through it or you may print key-value from that object.

alert(orderline.forEach(function(k,v){k + " => + v}));

Or you can loop through the orderlines.

for (line in orderline){
    alert(line.product_id);
}