Skip to content

Commit

Permalink
user can place order
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Oleynik committed Aug 26, 2016
1 parent 282e0dd commit 043c4b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
27 changes: 27 additions & 0 deletions app/commands/shopping_cart/place_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module ShoppingCart
class PlaceOrder < Rectify::Command
def initialize(order, params)
@order = order
@params = params
end

def call
place_order if order_valid?
end

private

def order_valid?
nested_models.all? { |model| @order.public_send(model).valid? }
end

def nested_models
[:shipping, :billing, :credit_card, :delivery]
end

def place_order
@order.completed
@order.save
end
end
end
4 changes: 4 additions & 0 deletions app/views/shopping_cart/checkout/_completed_buttons.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.raw
.col-md-12.text-left
= f.hidden_field :id
= back_to_shop_link
7 changes: 7 additions & 0 deletions app/views/shopping_cart/checkout/_final_step.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= render partial: 'ckeckout_header', locals: {step: @step}
%main.raw
= render partial: 'errors_messages', locals: {order: @order}
= form_for @order, url: wizard_path do |f|
= render partial: 'confirmation_details', locals: {order: @order, step: @step}
= render partial: 'confirmation_order', locals: {order: @order}
= render partial: template, locals: {f: f, order: @order}
1 change: 1 addition & 0 deletions app/views/shopping_cart/checkout/complete.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render partial: 'final_step', locals: {template: 'completed_buttons'}
8 changes: 1 addition & 7 deletions app/views/shopping_cart/checkout/confirm.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
= render partial: 'ckeckout_header', locals: {step: @step}
%main.raw
= render partial: 'errors_messages', locals: {order: @order}
= form_for @order, url: wizard_path do |f|
= render partial: 'confirmation_details', locals: {order: @order, step: @step}
= render partial: 'confirmation_order', locals: {order: @order}
= render partial: 'confirmation_buttons', locals: {f: f, order: @order}
= render partial: 'final_step', locals: {template: 'confirmation_buttons'}

0 comments on commit 043c4b3

Please sign in to comment.