Changeset 1341
- Timestamp:
- 02/27/07 10:00:40 (2 years ago)
- Files:
-
- peasantonline/app/controllers/admin_controller.rb (modified) (1 diff)
- peasantonline/app/controllers/catalog_controller.rb (modified) (4 diffs)
- peasantonline/app/helpers/application_helper.rb (modified) (1 diff)
- peasantonline/app/models/coupon.rb (added)
- peasantonline/app/views/admin/_form_coupons.rhtml (added)
- peasantonline/app/views/admin/_show_line_items.rhtml (modified) (2 diffs)
- peasantonline/app/views/admin/edit_coupons.rhtml (added)
- peasantonline/app/views/admin/list_coupons.rhtml (added)
- peasantonline/app/views/admin/new_coupons.rhtml (added)
- peasantonline/app/views/admin/show_coupons.rhtml (added)
- peasantonline/app/views/catalog/_left_nav.rhtml (modified) (1 diff)
- peasantonline/app/views/catalog/checkout.rhtml (modified) (1 diff)
- peasantonline/app/views/layouts/admin.rhtml (modified) (1 diff)
- peasantonline/db/migrate/029_create_coupons.rb (added)
- peasantonline/db/schema.rb (modified) (3 diffs)
- peasantonline/public/images/styleforum.jpg (added)
- peasantonline/public/stylesheets/catalog.css (modified) (1 diff)
- peasantonline/test/fixtures/coupons.yml (added)
- peasantonline/test/unit/coupon_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
peasantonline/app/controllers/admin_controller.rb
r1246 r1341 522 522 redirect_to :action => 'list_orders' 523 523 end 524 end 524 525 526 def list_coupons 527 @coupon_pages, @coupons = paginate :coupons, :per_page => 10 528 end 529 530 def show_coupons 531 @coupon = Coupon.find(params[:id]) 532 end 533 534 def new_coupons 535 @coupon = Coupon.new 536 end 537 538 def create_coupons 539 @coupon = Coupon.new(params[:coupon]) 540 if @coupon.save 541 flash[:notice] = 'Coupon was successfully created.' 542 redirect_to :action => 'list_coupons' 543 else 544 render :action => 'new_coupons' 545 end 546 end 547 548 def edit_coupons 549 @coupon = Coupon.find(params[:id]) 550 end 551 552 def update_coupons 553 @coupon = Coupon.find(params[:id]) 554 if @coupon.update_attributes(params[:coupon]) 555 flash[:notice] = 'Coupon was successfully updated.' 556 redirect_to :action => 'show_coupons', :id => @coupon 557 else 558 render :action => 'edit_coupons' 559 end 560 end 561 562 def destroy_coupons 563 Coupon.find(params[:id]).destroy 564 redirect_to :action => 'list_coupons' 565 end 566 end peasantonline/app/controllers/catalog_controller.rb
r1296 r1341 133 133 def save_order 134 134 @order = Order.new(params[:order]) 135 @coupon = Coupon.new(params[:coupon]) 136 @valid_coupon = Coupon.find_by_promo_code(@coupon.promo_code) 135 137 @order.add_line_items_from_cart(@cart) 138 139 @subtotal = @cart.total_price 140 if @valid_coupon 141 #Valid for this date? 142 143 if @valid_coupon.start_date <= Time.now and @valid_coupon.end_date >= Time.now 144 @order.coupon_id = @valid_coupon.id 145 146 if @valid_coupon.free_shipping == true 147 @order.shipping = 0 148 end 149 150 if @valid_coupon.offer_percent 151 @subtotal = @subtotal - ((@subtotal * @valid_coupon.offer_amount)/100) 152 else 153 if @valid_coupon.offer_amount < @subtotal 154 @subtotal = @subtotal - @valid_coupon.offer_amount 155 else 156 @subtotal = 0 157 end 158 end 159 end 160 end 136 161 137 162 @order.sales_tax = 0 … … 147 172 @transaction = Payment::AuthorizeNet.new( 148 173 :prefs => "#{RAILS_ROOT}/config/payment.yml", 149 :amount => @ cart.total_price+ @order.sales_tax + @order.shipping,174 :amount => @subtotal + @order.sales_tax + @order.shipping, 150 175 :expiration => credit_card_expiration_mmyy, 151 176 :first_name => @order.first_name, … … 162 187 @transaction = Payment::AuthorizeNet.new( 163 188 :prefs => "#{RAILS_ROOT}/config/payment.yml", 164 :amount => @ cart.total_price+ @order.sales_tax + @order.shipping,189 :amount => @subtotal + @order.sales_tax + @order.shipping, 165 190 :expiration => credit_card_expiration_mmyy, 166 191 :first_name => @order.first_name, … … 178 203 # "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) 179 204 if request.host_with_port == "localhost:3000" 180 redirect_to_thanks("Card processed successfully: localhost ")205 redirect_to_thanks("Card processed successfully: localhost - $" + (@subtotal + @order.sales_tax + @order.shipping).to_s) 181 206 else 182 207 begin peasantonline/app/helpers/application_helper.rb
r1296 r1341 17 17 return ["In Stock", "Sold Out"] 18 18 end 19 20 def get_1_100_list() 21 qty_arr = [] 22 qty_num = 1 23 24 100.times do 25 qty_arr[qty_num] = qty_num 26 qty_num = qty_num + 1 27 end 28 29 return qty_arr 30 end 31 32 def get_0_100_list() 33 qty_arr = [] 34 qty_num = 0 35 36 101.times do 37 qty_arr[qty_num] = qty_num 38 qty_num = qty_num + 1 39 end 40 41 return qty_arr 42 end 43 44 def get_true_false 45 return [['False', 0], ['True', 1]] 46 end 19 47 20 48 end peasantonline/app/views/admin/_show_line_items.rhtml
r1268 r1341 34 34 <% total_price += line_item.total_price %> 35 35 <% end %> 36 <%= 37 @valid_coupon = Coupon.find(@order.coupon_id) 38 @subtotal = total_price 39 @discount = 0 40 41 if @valid_coupon 42 #Valid for this date? 43 if @valid_coupon.offer_percent 44 @discount = (@subtotal * @valid_coupon.offer_amount)/100 45 else 46 if @valid_coupon.offer_amount < @subtotal 47 @discount = @valid_coupon.offer_amount 48 else 49 @discount = @subtotal 50 end 51 end 52 "<tr> 53 <td colspan='4'> 54 <b>Coupon Discount:</b> 55 </td> 56 <td> 57 <b>$#{@discount}</b> 58 </td> 59 </tr>" 60 end 61 %> 62 <tr> 63 <td colspan="4"> 64 <b>Order Total:</b> 65 </td> 66 <td> 67 <b>$<%= @order.shipping %></b> 68 </td> 69 </tr> 70 71 36 72 <tr> 37 73 <td colspan="4"> … … 39 75 </td> 40 76 <td> 41 <b>$<%= total_price %></b>77 <b>$<%= total_price + @order.shipping - @discount %></b> 42 78 </td> 43 79 </tr> peasantonline/app/views/catalog/_left_nav.rhtml
r1229 r1341 50 50 <p /> 51 51 <%= link_to "Store Policies", :controller=>"policy" %><br /><br /> 52 <img src="/images/gq100.gif" /> 52 <img class="partner-links" src="/images/gq100.gif" /> 53 <img class="partner-links" src="/images/styleforum.jpg" /> 53 54 </div> peasantonline/app/views/catalog/checkout.rhtml
r1293 r1341 846 846 <fieldset> 847 847 <legend>Other Order Information</legend> 848 848 <p> 849 <label for="coupon_promo_code">Coupon / Promo code</label><br /> 850 <%= text_field 'coupon', 'promo_code' %></p> 851 </p> 849 852 <p> 850 853 <label for="order_shipping">Shipping:</label><br /> peasantonline/app/views/layouts/admin.rhtml
r1061 r1341 25 25 <br /> 26 26 <%= link_to "Orders", :controller => 'admin', :action => 'list_orders' %> 27 <br /> 28 <%= link_to "Coupons", :controller => 'admin', :action => 'list_coupons' %> 27 29 </p> 28 30 peasantonline/db/schema.rb
r1296 r1341 3 3 # then regenerate this schema definition. 4 4 5 ActiveRecord::Schema.define(:version => 2 8) do5 ActiveRecord::Schema.define(:version => 29) do 6 6 7 7 create_table "categories", :force => true do |t| … … 10 10 t.column "long_description", :text 11 11 t.column "image", :string 12 end 13 14 create_table "coupons", :force => true do |t| 15 t.column "name", :string 16 t.column "description", :text 17 t.column "promo_code", :string 18 t.column "start_date", :datetime 19 t.column "end_date", :datetime 20 t.column "offer_amount", :integer 21 t.column "offer_percent", :boolean, :default => false 22 t.column "free_shipping", :boolean, :default => false 12 23 end 13 24 … … 61 72 t.column "cc_cvv", :integer 62 73 t.column "state_shipping", :string 74 t.column "coupon_id", :integer 63 75 end 76 77 add_index "orders", ["coupon_id"], :name => "fk_orders_coupons" 64 78 65 79 create_table "product_details", :force => true do |t| peasantonline/public/stylesheets/catalog.css
r1303 r1341 245 245 } 246 246 247 .partner-links { 248 padding-bottom: 5px; 249 } 250 247 251 .req { 248 252 border: 2px solid #EEEE66;