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:
addProduct: (product)->
if product.get('product_variants.length')
@target().modal 'product_variant_select', model: product
@modal 'product_variant_select', model: product
else
product.addOrderItem()
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
needs: ['application', 'table']
App.ProductOrdersComponent = Ember.Component.extend
orderTotal: (->
#Math.round(Math.random()*100)
@get('model').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('model.@each.quantity')
product_orders: (->@get('model')).property('model')
showTotal: (-> if @get('model.length') && @get('model.length') > 1 then true else false ).property('model.length')
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity')
#product_orders: (->@get('model')).property('model')
#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:
# clearProductOrders: ->
# #TODO: make clearing of unpersisted product orders
@@ -31,7 +31,7 @@ App.ProductOrdersController = Ember.Controller.extend
#orders = @store.all('product_order').toArray()
#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()
#@get('product_orders').forEach (product_order)-> dataObject['order'][product_order.get('product.id')] = product_order.get('quantity')
Ember.$.ajax
@@ -42,7 +42,7 @@ App.ProductOrdersController = Ember.Controller.extend
data: JSON.stringify(dataObject)
success: (response) =>
@store.pushPayload(order: response.order) if response.order
@transitionToRoute 'active_list'
@get('reference_controller').transitionToRoute 'active_list'
@get('product_orders').invoke 'unloadRecord'
removeProductOrder: (product_order)->
@@ -1,5 +1,4 @@
App.ApplicationController = Ember.Controller.extend
needs: ['product_orders']
#list: Ember.computed.alias 'globals.list'
#notice: ''
actions:
@@ -1,4 +1,5 @@
@App.modals.ProductVariantSelectController = @App.modals.BaseController.extend
title_path: 'product_variant.select_on_order.title'
actions:
chooseProductVariant: (product_variant)->
@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
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')
unordered_product_orders: Ember.computed -> @store.peekAll('product_order').filterBy('id', null)
actions:
joinOccupiedTable: ->
Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id'))
@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
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('id'))
#@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id'))
controller.secured ->
faye = new Faye.Client($event_host)
user_id = Qstorage.getItem('user_id')
@@ -1,4 +1,4 @@
each user in list.users
each list.users as |user|
user.avatar_tag
.display-row
.display-label=t 'attributes.list.created_at'
@@ -16,7 +16,7 @@ if list.closed_at
if list.orders.isLoaded
if list.sorted_orders
.list-orders-container
each order in list.sorted_orders
each list.sorted_orders as |order|
= list-order order=order
/= order.display
/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}"
if product_category.products
h4.product_category-title{action "toggleProductCategory" product_category}
@@ -9,5 +9,5 @@ each product_category in active_product_categories
= product_category.name
unless product_category.collapsed
ul.product_category-products
each product in product_category.sorted_products
each product_category.sorted_products as |product|
= menu-product product=product orderProducts=orderProducts
@@ -1,6 +1,6 @@
.panel
ul.product-orders
each product_order in product_orders
each product_orders as |product_order|
li.product-order
= product_order.display
button.product-order-remove.right{action "removeProductOrder" product_order}: span.icon
@@ -1,6 +1,6 @@
.row
h2= t 'join_request.existing_user.title'
each join_request in join_requests
each join_requests as |join_request|
.join-request-container
= join_request.user.avatar_tag
span.user-name= join_request.user.name
@@ -1,6 +1,6 @@
.row
h2=t 'models.plural.list'
each list in lists
each lists as |list|
= view "list-index" content=list
.clearfix
if hasMore
@@ -1,8 +1,8 @@
if model.image
.right: img src=model.image.small alt=""
each product_variant in product_variants
each model.product_variants as |product_variant|
.row
.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
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}"
@@ -3,7 +3,7 @@
.display-row
.display-label=t 'settings.language'
.display-field
each locale in locales
each locales as |locale|
= view 'settings-locale' locale=locale
.display-row
.display-label  
@@ -13,6 +13,6 @@
button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table'
if tableCanTakeOrders
.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
.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",
# scope: 'email,user_birthday,publish_stream'
config.omniauth :facebook, "653729178057509", "d4cea86f70803f1b75ed03c506a4d78e",
scope: 'email,user_birthday,publish_stream'
scope: 'email,user_birthday,publish_actions'
config.omniauth :instagram, "cd7bdfbee825499b94fb3783d1bc143b", "6b4f9ecf251c462993a696eebc0189be"
else
config.omniauth :facebook, "168928633304849", "22bc53e1a390c1e62d004195c55fe336",
scope: 'email,user_birthday,publish_stream'
scope: 'email,user_birthday,publish_actions'
config.omniauth :instagram, "81c78b969a7046d6b6b5b5fe3f30929c", "3697c16762ad4f1ca088e829efbaddde"
end
+4
View File
@@ -143,3 +143,7 @@ en:
modal:
info:
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:
info:
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
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
Scenario: Resetting an active order
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
@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
end
@@ -82,6 +82,16 @@ end
step "the user order total should not be visible for only one order" do
page.should_not have_selector ".product-orders .total"
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
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