Product variant fix

This commit is contained in:
2015-08-13 16:53:34 +02:00
parent 0415603a49
commit 6e97f74b0a
23 changed files with 72 additions and 26 deletions
@@ -9,8 +9,8 @@ App.MenuProductComponent = Ember.Component.extend
actions: actions:
addProduct: (product)-> addProduct: (product)->
if product.get('product_variants.length') if product.get('product_variants.length')
@target().modal 'product_variant_select', model: product @modal 'product_variant_select', model: product
else else
product.addOrderItem() product.addOrderItem()
showProductDescription: (product)-> showProductDescription: (product)->
@target().modal 'product_info', model: product, title: product.get('name') @modal 'product_info', model: product, title: product.get('name')
@@ -1,11 +1,11 @@
App.ProductOrdersController = Ember.Controller.extend App.ProductOrdersComponent = Ember.Component.extend
needs: ['application', 'table']
orderTotal: (-> orderTotal: (->
#Math.round(Math.random()*100) #Math.round(Math.random()*100)
@get('model').getEach('total').reduce(((sum, total) -> sum + total), 0) @get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('model.@each.quantity') ).property('product_orders.@each.quantity')
product_orders: (->@get('model')).property('model') #product_orders: (->@get('model')).property('model')
showTotal: (-> if @get('model.length') && @get('model.length') > 1 then true else false ).property('model.length') #product_orders: -> @store.peekAll('product_order')
showTotal: (-> if @get('product_orders.length') && @get('product_orders.length') > 1 then true else false ).property('product_orders.length')
actions: actions:
# clearProductOrders: -> # clearProductOrders: ->
# #TODO: make clearing of unpersisted product orders # #TODO: make clearing of unpersisted product orders
@@ -31,7 +31,7 @@ App.ProductOrdersController = Ember.Controller.extend
#orders = @store.all('product_order').toArray() #orders = @store.all('product_order').toArray()
#data = @get('product_orders').map( (po)->po.serialize() ) #data = @get('product_orders').map( (po)->po.serialize() )
dataObject = {table_id: @get('controllers.table.model.id')} dataObject = {table_id: @get('table.id')}
dataObject.product_orders = @get('product_orders').map( (po) -> po.serialize()).toArray() dataObject.product_orders = @get('product_orders').map( (po) -> po.serialize()).toArray()
#@get('product_orders').forEach (product_order)-> dataObject['order'][product_order.get('product.id')] = product_order.get('quantity') #@get('product_orders').forEach (product_order)-> dataObject['order'][product_order.get('product.id')] = product_order.get('quantity')
Ember.$.ajax Ember.$.ajax
@@ -42,7 +42,7 @@ App.ProductOrdersController = Ember.Controller.extend
data: JSON.stringify(dataObject) data: JSON.stringify(dataObject)
success: (response) => success: (response) =>
@store.pushPayload(order: response.order) if response.order @store.pushPayload(order: response.order) if response.order
@transitionToRoute 'active_list' @get('reference_controller').transitionToRoute 'active_list'
@get('product_orders').invoke 'unloadRecord' @get('product_orders').invoke 'unloadRecord'
removeProductOrder: (product_order)-> removeProductOrder: (product_order)->
@@ -1,5 +1,4 @@
App.ApplicationController = Ember.Controller.extend App.ApplicationController = Ember.Controller.extend
needs: ['product_orders']
#list: Ember.computed.alias 'globals.list' #list: Ember.computed.alias 'globals.list'
#notice: '' #notice: ''
actions: actions:
@@ -1,4 +1,5 @@
@App.modals.ProductVariantSelectController = @App.modals.BaseController.extend @App.modals.ProductVariantSelectController = @App.modals.BaseController.extend
title_path: 'product_variant.select_on_order.title'
actions: actions:
chooseProductVariant: (product_variant)-> chooseProductVariant: (product_variant)->
@get('model').addOrderItem(product_variant: product_variant.get('name')) @get('model').addOrderItem(product_variant: product_variant.get('name'))
@@ -16,7 +16,9 @@ App.TableController = Ember.Controller.extend
return false if @get('globals.list') # if you already have an active list, do not join another return false if @get('globals.list') # if you already have an active list, do not join another
if @get('model.occupied') then true else false # no point in joining tables that are not occupied if @get('model.occupied') then true else false # no point in joining tables that are not occupied
).property('globals.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'globals.list.table.id') ).property('globals.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'globals.list.table.id')
unordered_product_orders: Ember.computed -> @store.peekAll('product_order').filterBy('id', null)
actions: actions:
joinOccupiedTable: -> joinOccupiedTable: ->
Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id')) Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id'))
@set 'globals.join_request_sent', true # keeps the button deactivated @set 'globals.join_request_sent', true # keeps the button deactivated
#setupProductOrders: (-> @set('unordered_product_orders', @store.peekAll('product_order'))).on('init')
@@ -0,0 +1,6 @@
ComponentExtensions = Ember.Mixin.create
modal: (name, options={})->
target = App.__container__.lookup('route:application')
target.send "openModal", name, options
Ember.Component.reopen ComponentExtensions
@@ -1,7 +1,7 @@
App.ApplicationRoute = Ember.Route.extend App.ApplicationRoute = Ember.Route.extend
setupController: (controller)-> setupController: (controller)->
#@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('order')) # does not work (yet) #@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('order')) # does not work (yet)
@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id')) #@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id'))
controller.secured -> controller.secured ->
faye = new Faye.Client($event_host) faye = new Faye.Client($event_host)
user_id = Qstorage.getItem('user_id') user_id = Qstorage.getItem('user_id')
@@ -1,4 +1,4 @@
each user in list.users each list.users as |user|
user.avatar_tag user.avatar_tag
.display-row .display-row
.display-label=t 'attributes.list.created_at' .display-label=t 'attributes.list.created_at'
@@ -16,7 +16,7 @@ if list.closed_at
if list.orders.isLoaded if list.orders.isLoaded
if list.sorted_orders if list.sorted_orders
.list-orders-container .list-orders-container
each order in list.sorted_orders each list.sorted_orders as |order|
= list-order order=order = list-order order=order
/= order.display /= order.display
/span.currency= currency order.total /span.currency= currency order.total
@@ -1,4 +1,4 @@
each product_category in active_product_categories each active_product_categories as |product_category|
.product-category-container id="product-category-#{unbound product_category.id}" .product-category-container id="product-category-#{unbound product_category.id}"
if product_category.products if product_category.products
h4.product_category-title{action "toggleProductCategory" product_category} h4.product_category-title{action "toggleProductCategory" product_category}
@@ -9,5 +9,5 @@ each product_category in active_product_categories
= product_category.name = product_category.name
unless product_category.collapsed unless product_category.collapsed
ul.product_category-products ul.product_category-products
each product in product_category.sorted_products each product_category.sorted_products as |product|
= menu-product product=product orderProducts=orderProducts = menu-product product=product orderProducts=orderProducts
@@ -1,6 +1,6 @@
.panel .panel
ul.product-orders ul.product-orders
each product_order in product_orders each product_orders as |product_order|
li.product-order li.product-order
= product_order.display = product_order.display
button.product-order-remove.right{action "removeProductOrder" product_order}: span.icon button.product-order-remove.right{action "removeProductOrder" product_order}: span.icon
@@ -1,6 +1,6 @@
.row .row
h2= t 'join_request.existing_user.title' h2= t 'join_request.existing_user.title'
each join_request in join_requests each join_requests as |join_request|
.join-request-container .join-request-container
= join_request.user.avatar_tag = join_request.user.avatar_tag
span.user-name= join_request.user.name span.user-name= join_request.user.name
@@ -1,6 +1,6 @@
.row .row
h2=t 'models.plural.list' h2=t 'models.plural.list'
each list in lists each lists as |list|
= view "list-index" content=list = view "list-index" content=list
.clearfix .clearfix
if hasMore if hasMore
@@ -1,8 +1,8 @@
if model.image if model.image
.right: img src=model.image.small alt="" .right: img src=model.image.small alt=""
each product_variant in product_variants each model.product_variants as |product_variant|
.row .row
.small-8.columns: a{action "chooseProductVariant" product_variant}= product_variant.name .small-8.columns: a{action "chooseProductVariant" product_variant}= product_variant.name
.small-4.columns: a.choose-product-variant-button{action "chooseProductVariant" product_variant}= t 'product_variant.choose' .small-4.columns: a.choose-product-variant-button{action "chooseProductVariant" product_variant}= t 'product_variant.select_on_order.choose'
hr hr
button.modal-close{action "close"}= t 'modal.info.close' button.modal-close{action "close"}= t 'modal.info.close'
@@ -1,2 +1,2 @@
each table in tables each tables as |table|
a{action "selectQr" table}: img src="/table_qr_image.svg?table_id=#{unbound table._id}" a{action "selectQr" table}: img src="/table_qr_image.svg?table_id=#{unbound table._id}"
@@ -3,7 +3,7 @@
.display-row .display-row
.display-label=t 'settings.language' .display-label=t 'settings.language'
.display-field .display-field
each locale in locales each locales as |locale|
= view 'settings-locale' locale=locale = view 'settings-locale' locale=locale
.display-row .display-row
.display-label   .display-label  
@@ -13,6 +13,6 @@
button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table' button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table'
if tableCanTakeOrders if tableCanTakeOrders
.large-6.columns= menu-product-categories product_categories=supplier.product_categories orderProducts=true .large-6.columns= menu-product-categories product_categories=supplier.product_categories orderProducts=true
.large-6.columns= render 'product_orders' .large-6.columns= product-orders table=model product_orders=unordered_product_orders reference_controller=controller
else else
.large12= menu-product-categories product_categories=supplier.product_categories orderProducts=false .large12= menu-product-categories product_categories=supplier.product_categories orderProducts=false
+2 -2
View File
@@ -238,11 +238,11 @@ Devise.setup do |config|
# config.omniauth :facebook, "505160086210072", "fcc474a3fb13c6bcc0f7c83a92ad1b17", # config.omniauth :facebook, "505160086210072", "fcc474a3fb13c6bcc0f7c83a92ad1b17",
# scope: 'email,user_birthday,publish_stream' # scope: 'email,user_birthday,publish_stream'
config.omniauth :facebook, "653729178057509", "d4cea86f70803f1b75ed03c506a4d78e", config.omniauth :facebook, "653729178057509", "d4cea86f70803f1b75ed03c506a4d78e",
scope: 'email,user_birthday,publish_stream' scope: 'email,user_birthday,publish_actions'
config.omniauth :instagram, "cd7bdfbee825499b94fb3783d1bc143b", "6b4f9ecf251c462993a696eebc0189be" config.omniauth :instagram, "cd7bdfbee825499b94fb3783d1bc143b", "6b4f9ecf251c462993a696eebc0189be"
else else
config.omniauth :facebook, "168928633304849", "22bc53e1a390c1e62d004195c55fe336", config.omniauth :facebook, "168928633304849", "22bc53e1a390c1e62d004195c55fe336",
scope: 'email,user_birthday,publish_stream' scope: 'email,user_birthday,publish_actions'
config.omniauth :instagram, "81c78b969a7046d6b6b5b5fe3f30929c", "3697c16762ad4f1ca088e829efbaddde" config.omniauth :instagram, "81c78b969a7046d6b6b5b5fe3f30929c", "3697c16762ad4f1ca088e829efbaddde"
end end
+4
View File
@@ -143,3 +143,7 @@ en:
modal: modal:
info: info:
close: Close close: Close
product_variant:
select_on_order:
title: "What variant of %{name} do you want?"
choose: Choose
+4
View File
@@ -143,3 +143,7 @@ nl:
modal: modal:
info: info:
close: Sluit close: Sluit
product_variant:
select_on_order:
title: "Selecteer welke variant %{name} je wilt"
choose: Kies
@@ -25,6 +25,17 @@ Feature: Ordering a product as a user
When the user orders list gets closed When the user orders list gets closed
Then the user should be redirected to the archived list path Then the user should be redirected to the archived list path
@javascript
Scenario: Order a product with product variants
Given there is an open supplier with a menu
And I am signed in as a user
And I am on the user homepage
When the user scans a table QR code
And the user clicks on the order product button 'Australian beer'
And the user selects the product variant 'Without foam'
Then the user order 'Australian beer' with variant 'Without foam' should be in the order list
#TODO: MORE ADVANCED TEST
@javascript @javascript
Scenario: Resetting an active order Scenario: Resetting an active order
Given there is an open supplier with a menu Given there is an open supplier with a menu
+3
View File
@@ -6,6 +6,9 @@ step "there is an open supplier with a menu" do
@apple_pie= create :product, name: 'Apple pie', supplier: @supplier, price: 4.28, product_category_id: @category_lunch.id @apple_pie= create :product, name: 'Apple pie', supplier: @supplier, price: 4.28, product_category_id: @category_lunch.id
@heineken_beer = create :product, name: 'Heineken beer', supplier: @supplier, price: 2.34, product_category_id: @category_beer.id @heineken_beer = create :product, name: 'Heineken beer', supplier: @supplier, price: 2.34, product_category_id: @category_beer.id
@australian_beer = create :product, name: 'Australian beer', supplier: @supplier, price: 3.34, product_category_id: @category_beer.id
create :product_variant, product: @australian_beer, name: 'With foam'
create :product_variant, product: @australian_beer, name: 'Without foam'
@product = @heineken_beer # set @product for user order selection @product = @heineken_beer # set @product for user order selection
end end
@@ -82,6 +82,16 @@ end
step "the user order total should not be visible for only one order" do step "the user order total should not be visible for only one order" do
page.should_not have_selector ".product-orders .total" page.should_not have_selector ".product-orders .total"
end end
step "the user selects the product variant :variant" do |variant|
# Manual in stead of js_click because capybara does not support the contains statement
#find ".modal .choose-product-variant-button"
find ".modal"
page.evaluate_script %|$('.modal a:contains("#{variant}")').click()|
end
step "the user order :product_name with variant :variant should be in the order list" do |product_name, variant|
page.should have_content "1 x #{product_name} (#{variant})"
end
step "the user order total should be visible with the correct total price" do step "the user order total should be visible with the correct total price" do
within ".product-orders .total" do within ".product-orders .total" do
+6
View File
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :product_variant do
sequence(:name){|i| "Variant #{i}"}
association :product
end
end