Continue adding product variants

This commit is contained in:
2015-04-13 17:57:06 +02:00
parent 6746eaa383
commit 2b036368cf
32 changed files with 169 additions and 12224 deletions
@@ -6,5 +6,26 @@ App.Product = DS.Model.extend
position: attr('number', defaultValue: 0)
active: attr 'boolean', defaultValue: true
image: attr()
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
product_category: DS.belongsTo('product-category')
product_orders: DS.hasMany('product-order')
product_variants: DS.hasMany 'product-variant'
sorted_product_variants: Ember.computed 'product_variants.@each.name', 'product_variants.@each.position', ->
@get('product_variants').sortBy('position')
variantsDisplay: Ember.computed 'sorted_product_variants', ->
@get('sorted_product_variants').mapBy('name').join(', ')
addOrderItem: (options = {})->
#if existing = @store.all('product_order').find((po)-> po.get('product') == product and not po.get('order'))
if options.product_variant
existing = @get('product_orders').find( (po)-> !po.get('order') and po.get('product_variant') is options.product_variant )
else
existing = @get('product_orders').find( (po)-> !po.get('order') )
if existing
existing.increment()
else
@store.createRecord 'product_order',
product: this
price: @get('price')
product_variant: options.product_variant