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
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
+ @during_checkout = false
end
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
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
<% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>
<% end -%>
-
- <%= yield :layout %>
+ <div id="main_panel">
+ <%= yield :layout %>
+ </div>
</div>
</div>
</body>
</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 %>
page.replace_html("main_panel", :partial => "checkout", :object => @order)
+
+if page[:during_checkout]
+ page.select("div#checkout_buttons").each {|div| div.hide}
+end
-<div id="main_panel">
<h1>Neil's Whimsical Store Catalogue</h1>
<% for product in @products -%>
</div>
</div>
<% end %>
-</div>
+