attr = DS.attr
App.ProductOrder = DS.Model.extend
  quantity: attr 'number', defaultValue: 1
  price: attr 'number'
  product_name: attr 'string'
  product_variant: attr('string')
  placed: attr('boolean', defaultValue: false) # virtual attribute for new orders to be placed, should be more elegant
  product: DS.belongsTo('product', async: true)
  order: DS.belongsTo('order', async: false)
  increment: ->
    @set('quantity', @get('quantity') + 1)
  total: (-> @get('quantity') * @get('price')).property('quantity', 'price')
  display: Ember.computed 'quantity', 'product_variant', 'product_name', ->
    disp = "#{@get('quantity')} x #{@get('product_name')}"
    if variant = @get('product_variant')
      disp = "#{disp} (#{variant})"
    disp.htmlSafe()
  setOrder: (order)->
    @set('placed', true)
    @set('order', order)
