Changeset 1268
- Timestamp:
- 11/30/06 22:59:44 (2 years ago)
- Files:
-
- peasantonline/app/controllers/catalog_controller.rb (modified) (3 diffs)
- peasantonline/app/models/cart.rb (modified) (1 diff)
- peasantonline/app/models/cart_item.rb (modified) (1 diff)
- peasantonline/app/models/line_item.rb (modified) (1 diff)
- peasantonline/app/views/admin/_show_line_items.rhtml (modified) (3 diffs)
- peasantonline/db/migrate/027_add_product_detail_to_line_items.rb (added)
- peasantonline/db/schema.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
peasantonline/app/controllers/catalog_controller.rb
r1262 r1268 102 102 redirect_to_index("Invalid size") 103 103 else 104 @current_item = @cart.add_product(@product, @product_detail.size )104 @current_item = @cart.add_product(@product, @product_detail.size, @product_detail) 105 105 @product_details = ProductDetail.find_all_by_product(params[:id]) 106 106 redirect_to_index unless request.xhr? … … 163 163 #redirect_to_thanks( 164 164 # "Card processed successfully: #{@transaction.authorization}<p />" + " <b>Order details</b>:<br /> #{@order.first_name} #{@order.last_name}<p />" + " #{@order.address}<br />" + " #{@order.address_2}<br />" + " #{@order.city}, " + " #{@order.state}<br />" + " #{@order.zip}, " + "#{@order.country}<br />" + " #{@order.phone}<br />" + " #{@order.email}<p />" + " Comments: #{@order.comments}<p />" + " Sub-total: $#{@cart.total_price}<br />" + " Sales Tax: $#{@order.sales_tax}<br />" + " Shipping: $#{@order.shipping}<br />" + "------------------<br />" + " Total: $" + (@cart.total_price + @order.sales_tax + @order.shipping).to_s) 165 165 if request.host_with_port == "localhost:3000" 166 redirect_to_thanks("Card processed successfully: localhost") 167 else 166 168 begin 167 169 @transaction.submit … … 173 175 redirect_to_index("Card was rejected: #{@transaction.error_message}") 174 176 end 177 end 175 178 176 179 else peasantonline/app/models/cart.rb
r1133 r1268 11 11 end 12 12 13 def add_product(product, size )13 def add_product(product, size, product_detail) 14 14 current_item = @items.find {|item| item.product == product && item.size == size} 15 15 if current_item 16 16 current_item.increment_quantity 17 17 else 18 current_item = CartItem.new(product, size )18 current_item = CartItem.new(product, size, product_detail) 19 19 @items << current_item 20 20 end peasantonline/app/models/cart_item.rb
r1038 r1268 1 1 class CartItem 2 2 include Reloadable 3 attr_reader :product, :size, :quantity 3 attr_reader :product, :size, :quantity, :product_detail 4 4 5 def initialize(product, size) 6 @product = product 5 def initialize(product, size, product_detail) 6 @product = product 7 @product_detail = product_detail 7 8 @quantity = 1 8 9 @size = size peasantonline/app/models/line_item.rb
r1042 r1268 2 2 belongs_to :order 3 3 belongs_to :product 4 belongs_to :product_detail 4 5 5 6 def self.from_cart_item(cart_item) 6 7 li = self.new 7 8 li.product = cart_item.product 9 li.product_detail = cart_item.product_detail 8 10 li.size = cart_item.size 9 11 li.quantity = cart_item.quantity peasantonline/app/views/admin/_show_line_items.rhtml
r1057 r1268 5 5 <th>Name</th> 6 6 <th>Size</th> 7 <th>Color</th> 7 8 <th>Quantity</th> 8 9 <th>Price</th> … … 18 19 </td> 19 20 <td> 21 <%= 22 if line_item.product_detail 23 line_item.product_detail.color 24 end 25 %> 26 </td> 27 <td> 20 28 <%= line_item.quantity %> 21 29 </td> … … 27 35 <% end %> 28 36 <tr> 29 <td colspan=" 3">37 <td colspan="4"> 30 38 <b>Order Total:</b> 31 39 </td> peasantonline/db/schema.rb
r1260 r1268 3 3 # then regenerate this schema definition. 4 4 5 ActiveRecord::Schema.define(:version => 2 6) do5 ActiveRecord::Schema.define(:version => 27) do 6 6 7 7 create_table "categories", :force => true do |t| … … 25 25 t.column "total_price", :integer, :default => 0, :null => false 26 26 t.column "size", :string 27 t.column "product_detail_id", :integer 27 28 end 28 29 29 30 add_index "line_items", ["product_id"], :name => "fk_line_item_products" 30 31 add_index "line_items", ["order_id"], :name => "fk_line_item_orders" 32 add_index "line_items", ["product_detail_id"], :name => "fk_line_item_product_details" 31 33 32 34 create_table "orders", :force => true do |t|