Setup of product variants
This commit is contained in:
@@ -10,6 +10,7 @@ App.Product = DS.Model.extend Ember.Validations.Mixin,
|
||||
image: attr()
|
||||
product_category: DS.belongsTo('product_category')
|
||||
product_orders: DS.hasMany('product_order')
|
||||
product_variants: DS.hasMany('product_variant')
|
||||
|
||||
image_src: (->
|
||||
image = @get('image')
|
||||
@@ -18,6 +19,12 @@ App.Product = DS.Model.extend Ember.Validations.Mixin,
|
||||
image
|
||||
).property('image')
|
||||
|
||||
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(', ')
|
||||
|
||||
#isValid: (->
|
||||
#return false unless price = @get('price')
|
||||
#return false unless "#{price}".match(/^[+-]?\d+(\.?\d?\d)?$/)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
attr = DS.attr
|
||||
App.ProductVariant = DS.Model.extend Ember.Validations.Mixin,
|
||||
name: attr 'string'
|
||||
product: DS.belongsTo 'product'
|
||||
position: attr 'number', defaultValue: 0
|
||||
validations:
|
||||
name:
|
||||
presence: true
|
||||
Reference in New Issue
Block a user