projects
/
depot.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
951fe14
)
Decoupled carts and orders
author
Neil Smith
<neil.git@njae.me.uk>
Mon, 9 Mar 2009 11:18:12 +0000
(11:18 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Mon, 9 Mar 2009 11:18:12 +0000
(11:18 +0000)
app/controllers/store_controller.rb
patch
|
blob
|
history
app/models/line_item.rb
patch
|
blob
|
history
app/models/order.rb
patch
|
blob
|
history
app/views/layouts/store.html.erb
patch
|
blob
|
history
app/views/store/_cart.html.erb
patch
|
blob
|
history
app/views/store/checkout.js.rjs
patch
|
blob
|
history
app/views/store/index.html.erb
patch
|
blob
|
history
diff --git
a/app/controllers/store_controller.rb
b/app/controllers/store_controller.rb
index de9e160be607cd54c7522ee77ad512f3ffa2640c..68939e6b09f31a82539e7ae7335eb80ce4466919 100644
(file)
--- a/
app/controllers/store_controller.rb
+++ b/
app/controllers/store_controller.rb
@@
-28,6
+28,7
@@
class StoreController < ApplicationController
redirect_to_index("Your cart is empty" )
else
@order = Order.new
redirect_to_index("Your cart is empty" )
else
@order = Order.new
+ @during_checkout = true
respond_to do |format|
format.js if request.xhr?
format.html
respond_to do |format|
format.js if request.xhr?
format.html
@@
-38,13
+39,21
@@
class StoreController < ApplicationController
def save_order
@cart = find_cart
@order = Order.new(params[:order])
def save_order
@cart = find_cart
@order = Order.new(params[:order])
- @order.add_line_items_from_cart(@cart)
+ # @order.add_line_items_from_cart(@cart)
+ @cart.items.each do |item|
+ li = LineItem.new
+ li.product = item.product
+ li.quantity = item.quantity
+ li.total_price = item.price
+ @order.line_items << li
+ end
if @order.save
session[:cart] = nil
redirect_to_index("Thank you for your order")
else
render :action => 'checkout'
end
if @order.save
session[:cart] = nil
redirect_to_index("Thank you for your order")
else
render :action => 'checkout'
end
+ @during_checkout = false
end
end
diff --git
a/app/models/line_item.rb
b/app/models/line_item.rb
index 61161a02a87601a5cf550bf08fd26cb071d80c20..3e3afed73532113bdaae232dbbf698c4d97fff0d 100644
(file)
--- a/
app/models/line_item.rb
+++ b/
app/models/line_item.rb
@@
-2,11
+2,11
@@
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product
belongs_to :order
belongs_to :product
- def self.from_cart_item(cart_item)
- li = self.new
- li.product = cart_item.product
- li.quantity = cart_item.quantity
- li.total_price = cart_item.price
- li
- end
+
#
def self.from_cart_item(cart_item)
+
#
li = self.new
+
#
li.product = cart_item.product
+
#
li.quantity = cart_item.quantity
+
#
li.total_price = cart_item.price
+
#
li
+
#
end
end
end
diff --git
a/app/models/order.rb
b/app/models/order.rb
index bea4da6c367ca64ffc28bd46b63ad68769677126..3da7154ae29ed7b7c35e2e1f6da742ffe637ef93 100644
(file)
--- a/
app/models/order.rb
+++ b/
app/models/order.rb
@@
-11,10
+11,10
@@
class Order < ActiveRecord::Base
validates_inclusion_of :pay_type, :in =>
PAYMENT_TYPES.map {|disp, value| value}
validates_inclusion_of :pay_type, :in =>
PAYMENT_TYPES.map {|disp, value| value}
- def add_line_items_from_cart(cart)
- cart.items.each do |item|
- li = LineItem.from_cart_item(item)
- line_items << li
- end
- end
+
#
def add_line_items_from_cart(cart)
+
#
cart.items.each do |item|
+
#
li = LineItem.from_cart_item(item)
+
#
line_items << li
+
#
end
+
#
end
end
end
diff --git
a/app/views/layouts/store.html.erb
b/app/views/layouts/store.html.erb
index 63c7dd919a1df2a531a3c8bec20615df861387bd..b1f928e99aa5dd06fc4e613f969626f74767372d 100644
(file)
--- a/
app/views/layouts/store.html.erb
+++ b/
app/views/layouts/store.html.erb
@@
-26,8
+26,9
@@
<% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>
<% end -%>
<% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>
<% end -%>
-
- <%= yield :layout %>
+ <div id="main_panel">
+ <%= yield :layout %>
+ </div>
</div>
</div>
</body>
</div>
</div>
</body>
diff --git
a/app/views/store/_cart.html.erb
b/app/views/store/_cart.html.erb
index 43e9a162a543f653864065095d9697a81a3e5038..313d23e5cd072d276050de69dd43db8aa69ba85b 100644
(file)
--- a/
app/views/store/_cart.html.erb
+++ b/
app/views/store/_cart.html.erb
@@
-8,10
+8,14
@@
</tr>
</table>
</tr>
</table>
-<% form_remote_tag :url => {:action => 'checkout'} do %>
- <%= submit_tag "Checkout" %>
-<% end %>
+<% unless @during_checkout %>
+ <div id="checkout_buttons">
+ <% form_remote_tag :url => {:action => 'checkout'} do %>
+ <%= submit_tag "Checkout" %>
+ <% end %>
-<% form_remote_tag :url => {:action => 'empty_cart'} do %>
- <%= submit_tag "Empty cart" %>
+ <% form_remote_tag :url => {:action => 'empty_cart'} do %>
+ <%= submit_tag "Empty cart" %>
+ <% end %>
+ </div>
<% end %>
<% end %>
diff --git
a/app/views/store/checkout.js.rjs
b/app/views/store/checkout.js.rjs
index d819e16e17b95f780a51499d5de3ea982c7c3d6c..610f9b18e2bc8dc61065015844e31f41b194152d 100644
(file)
--- a/
app/views/store/checkout.js.rjs
+++ b/
app/views/store/checkout.js.rjs
@@
-1
+1,5
@@
page.replace_html("main_panel", :partial => "checkout", :object => @order)
page.replace_html("main_panel", :partial => "checkout", :object => @order)
+
+if page[:during_checkout]
+ page.select("div#checkout_buttons").each {|div| div.hide}
+end
diff --git
a/app/views/store/index.html.erb
b/app/views/store/index.html.erb
index 63c12da3a258b96303b2a1a59169baabab38cea0..7bbc2abaad5eab95d8f72a1d949edc92443cb10e 100644
(file)
--- a/
app/views/store/index.html.erb
+++ b/
app/views/store/index.html.erb
@@
-1,4
+1,3
@@
-<div id="main_panel">
<h1>Neil's Whimsical Store Catalogue</h1>
<% for product in @products -%>
<h1>Neil's Whimsical Store Catalogue</h1>
<% for product in @products -%>
@@
-16,4
+15,4
@@
</div>
</div>
<% end %>
</div>
</div>
<% end %>
-</div>
+