Changeset 1341

Show
Ignore:
Timestamp:
02/27/07 10:00:40 (2 years ago)
Author:
james
Message:

coupon model

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • peasantonline/app/controllers/admin_controller.rb

    r1246 r1341  
    522522    redirect_to :action => 'list_orders' 
    523523end 
    524 end 
     524 
     525 
     526def list_coupons 
     527@coupon_pages, @coupons = paginate :coupons, :per_page => 10 
     528end 
     529 
     530def show_coupons 
     531@coupon = Coupon.find(params[:id]) 
     532end 
     533 
     534def new_coupons 
     535@coupon = Coupon.new 
     536end 
     537 
     538def create_coupons 
     539@coupon = Coupon.new(params[:coupon]) 
     540if @coupon.save 
     541  flash[:notice] = 'Coupon was successfully created.' 
     542  redirect_to :action => 'list_coupons' 
     543else 
     544  render :action => 'new_coupons' 
     545end 
     546end 
     547 
     548def edit_coupons 
     549@coupon = Coupon.find(params[:id]) 
     550end 
     551 
     552def update_coupons 
     553@coupon = Coupon.find(params[:id]) 
     554if @coupon.update_attributes(params[:coupon]) 
     555  flash[:notice] = 'Coupon was successfully updated.' 
     556  redirect_to :action => 'show_coupons', :id => @coupon 
     557else 
     558  render :action => 'edit_coupons' 
     559end 
     560end 
     561 
     562def destroy_coupons 
     563Coupon.find(params[:id]).destroy 
     564redirect_to :action => 'list_coupons' 
     565end 
     566end 
  • peasantonline/app/controllers/catalog_controller.rb

    r1296 r1341  
    133133        def save_order  
    134134                @order = Order.new(params[:order])  
     135                @coupon = Coupon.new(params[:coupon]) 
     136    @valid_coupon = Coupon.find_by_promo_code(@coupon.promo_code) 
    135137                @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 
    136161 
    137162    @order.sales_tax = 0 
     
    147172                    @transaction = Payment::AuthorizeNet.new( 
    148173                                 :prefs       => "#{RAILS_ROOT}/config/payment.yml", 
    149                                  :amount      => @cart.total_price + @order.sales_tax + @order.shipping, 
     174                                 :amount      => @subtotal + @order.sales_tax + @order.shipping, 
    150175                                 :expiration  => credit_card_expiration_mmyy, 
    151176                                 :first_name  => @order.first_name, 
     
    162187              @transaction = Payment::AuthorizeNet.new( 
    163188                                 :prefs       => "#{RAILS_ROOT}/config/payment.yml", 
    164                                  :amount      => @cart.total_price + @order.sales_tax + @order.shipping, 
     189                                 :amount      => @subtotal + @order.sales_tax + @order.shipping, 
    165190                                 :expiration  => credit_card_expiration_mmyy, 
    166191                                 :first_name  => @order.first_name, 
     
    178203                #  "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: &nbsp;$#{@order.shipping}<br />" + "------------------<br />" + " Total: &nbsp; &nbsp; $" + (@cart.total_price + @order.sales_tax + @order.shipping).to_s) 
    179204            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
    181206            else 
    182207              begin 
  • peasantonline/app/helpers/application_helper.rb

    r1296 r1341  
    1717    return ["In Stock", "Sold Out"] 
    1818  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 
    1947 
    2048end 
  • peasantonline/app/views/admin/_show_line_items.rhtml

    r1268 r1341  
    3434        <% total_price += line_item.total_price %> 
    3535<% end %> 
     36<%= 
     37@valid_coupon = Coupon.find(@order.coupon_id) 
     38@subtotal = total_price 
     39@discount = 0 
     40 
     41if @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>" 
     60end 
     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 
    3672        <tr> 
    3773                <td colspan="4"> 
     
    3975                </td> 
    4076                <td>     
    41                         <b>$<%= total_price %></b> 
     77                        <b>$<%= total_price + @order.shipping - @discount %></b> 
    4278                </td> 
    4379        </tr> 
  • peasantonline/app/views/catalog/_left_nav.rhtml

    r1229 r1341  
    5050    <p /> 
    5151        <%= 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" /> 
    5354        </div> 
  • peasantonline/app/views/catalog/checkout.rhtml

    r1293 r1341  
    846846                        <fieldset>  
    847847                                <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> 
    849852                <p> 
    850853                        <label for="order_shipping">Shipping:</label><br />  
  • peasantonline/app/views/layouts/admin.rhtml

    r1061 r1341  
    2525                        <br /> 
    2626                        <%= link_to "Orders", :controller => 'admin', :action => 'list_orders' %> 
     27                        <br /> 
     28                        <%= link_to "Coupons", :controller => 'admin', :action => 'list_coupons' %> 
    2729        </p> 
    2830  
  • peasantonline/db/schema.rb

    r1296 r1341  
    33# then regenerate this schema definition. 
    44 
    5 ActiveRecord::Schema.define(:version => 28) do 
     5ActiveRecord::Schema.define(:version => 29) do 
    66 
    77  create_table "categories", :force => true do |t| 
     
    1010    t.column "long_description", :text 
    1111    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 
    1223  end 
    1324 
     
    6172    t.column "cc_cvv", :integer 
    6273    t.column "state_shipping", :string 
     74    t.column "coupon_id", :integer 
    6375  end 
     76 
     77  add_index "orders", ["coupon_id"], :name => "fk_orders_coupons" 
    6478 
    6579  create_table "product_details", :force => true do |t| 
  • peasantonline/public/stylesheets/catalog.css

    r1303 r1341  
    245245} 
    246246 
     247.partner-links { 
     248        padding-bottom: 5px; 
     249} 
     250 
    247251.req { 
    248252border: 2px solid #EEEE66;