Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactored calculators to support configuration through admin interface.

  • Loading branch information...
commit dfcb54465e4cefde4279938edab1979a57d2d817 1 parent 795990d
Sean Schofield authored July 16, 2009

Showing 35 changed files with 260 additions and 156 deletions. Show diff stats Hide diff stats

  1. 1  .gitignore
  2. 2  app/controllers/admin/calculators_controller.rb
  3. 49  app/controllers/admin/shipping_methods_controller.rb
  4. 11  app/helpers/admin/base_helper.rb
  5. 2  app/helpers/admin/calculators_helper.rb
  6. 17  app/models/calculator.rb
  7. 2  app/models/shipping_calculator.rb
  8. 16  app/models/shipping_method.rb
  9. 12  app/views/admin/shipping_methods/_form.html.erb
  10. 2  app/views/admin/shipping_methods/edit.html.erb
  11. 2  app/views/admin/shipping_methods/index.html.erb
  12. 7  app/views/layouts/admin.html.erb
  13. 7  config/locales/en-US.yml
  14. 3  config/routes.rb
  15. 22  db/migrate/20090715172345_create_calculators.rb
  16. 12  db/sample/calculators.yml
  17. 15  db/sample/preferences.yml
  18. 13  db/sample/shipping_methods.yml
  19. 16  db/sample/zone_members.yml
  20. 6  db/sample/zones.yml
  21. 4  generate
  22. 13  public/javascripts/calculator.js
  23. 4  public/stylesheets/admin/admin.css
  24. 59  spec/models/shipping_method_spec.rb
  25. 12  test/factories.rb
  26. 7  test/fixtures/calculators.yml
  27. 8  test/functional/calculators_controller_test.rb
  28. 8  test/test_helper.rb
  29. 6  test/unit/calculator_test.rb
  30. 4  test/unit/helpers/calculators_helper_test.rb
  31. 37  test/unit/shppping_method_test.rb
  32. 7  vendor/extensions/flat_rate_shipping/app/models/flat_rate_shipping_calculator.rb
  33. 1  vendor/extensions/flat_rate_shipping/flat_rate_shipping_extension.rb
  34. 7  vendor/extensions/flat_rate_shipping/lib/flat_rate_shipping_configuration.rb
  35. 22  vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/config.rb
1  .gitignore
@@ -39,7 +39,6 @@ spree_dev
39 39
 spree_test
40 40
 tmp
41 41
 vendor/rails
42  
-vendor/extensions
43 42
 public/images/reviews_ratings.png
44 43
 public/javascripts/jquery.lightbox.js
45 44
 public/javascripts/jquery.product_reviews_ratings.*
2  app/controllers/admin/calculators_controller.rb
... ...
@@ -0,0 +1,2 @@
  1
+class Admin::CalculatorsController < Admin::BaseController
  2
+end
49  app/controllers/admin/shipping_methods_controller.rb
... ...
@@ -1,19 +1,34 @@
  1
+
  2
+
1 3
 class Admin::ShippingMethodsController < Admin::BaseController    
2  
-    resource_controller
3  
-    before_filter :load_data
4  
-    layout 'admin'
5  
-    
6  
-    update.response do |wants|
7  
-      wants.html { redirect_to collection_url }
8  
-    end
9  
-    
10  
-    
11  
-    create.response do |wants|
12  
-      wants.html { redirect_to collection_url }
13  
-    end
14  
-    
15  
-    private 
16  
-    def load_data     
17  
-      @available_zones = Zone.find :all, :order => :name
18  
-    end
  4
+  resource_controller
  5
+  before_filter :load_data
  6
+  layout 'admin'
  7
+       
  8
+  update.before do
  9
+    calc_type = params[:shipping_method][:calculator_type].constantize
  10
+    next if calc_type == @shipping_method.calculator.class
  11
+    @shipping_method.calculator = calc_type.new
  12
+    @shipping_method.save
  13
+  end
  14
+  
  15
+  update.response do |wants|
  16
+    wants.html { redirect_to collection_url }
  17
+  end  
  18
+  
  19
+  create.response do |wants|
  20
+    wants.html { redirect_to collection_url }
  21
+  end
  22
+  
  23
+  private       
  24
+  def build_object
  25
+    @object ||= end_of_association_chain.send parent? ? :build : :new, object_params 
  26
+    @object.calculator = params[:shipping_method][:calculator_type].constantize.new if params[:shipping_method]
  27
+  end
  28
+  
  29
+  def load_data     
  30
+    @available_zones = Zone.find :all, :order => :name                      
  31
+    # TODO - remove hard coded
  32
+    @shipping_calculators = [FlatRateShippingCalculator]
  33
+  end    
19 34
 end
11  app/helpers/admin/base_helper.rb
@@ -162,5 +162,14 @@ def remove_nested(fields)
162 162
     out << fields.hidden_field(:_delete) unless fields.object.new_record?
163 163
     out << (link_to icon("delete"), "#", :class => "remove")
164 164
     out
165  
-  end    
  165
+  end  
  166
+  
  167
+  def preference_fields(calculator, form)
  168
+    field_html = ""
  169
+    calculator.preferences.keys.each do |key|
  170
+      field_html += (form.label("preferred_#{key}", "#{t(key)}: "))
  171
+      field_html += (form.text_field("preferred_#{key}")) 
  172
+    end
  173
+    field_html
  174
+  end  
166 175
 end
2  app/helpers/admin/calculators_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module Admin::CalculatorsHelper
  2
+end
17  app/models/calculator.rb
... ...
@@ -0,0 +1,17 @@
  1
+class Calculator < ActiveRecord::Base  
  2
+  belongs_to :calculable, :polymorphic => true     
  3
+  validates_presence_of :calculable_id
  4
+    
  5
+  def self.shipping
  6
+    all.select { |c| c.is_a? ShippingCalculator }
  7
+  end
  8
+  
  9
+  def available?(order)
  10
+    true
  11
+  end 
  12
+
  13
+  def to_s
  14
+    self.class.to_s.titleize
  15
+  end      
  16
+  
  17
+end
2  app/models/shipping_calculator.rb
... ...
@@ -0,0 +1,2 @@
  1
+class ShippingCalculator < Calculator
  2
+end
16  app/models/shipping_method.rb
... ...
@@ -1,13 +1,23 @@
1 1
 class ShippingMethod < ActiveRecord::Base
2 2
   belongs_to :zone
3  
-
  3
+  has_one :calculator, :as => :calculable, :dependent => :destroy
  4
+                                    
  5
+  accepts_nested_attributes_for :calculator
  6
+   
  7
+  def calculator_type
  8
+    calculator.class.to_s if calculator
  9
+  end
  10
+  
  11
+  def calculator_type=(calculator_type)
  12
+    # does nothing - just here to satisfy the form
  13
+  end
  14
+  
4 15
   def calculate_shipping(shipment)
5 16
     return 0 unless zone.include?(shipment.address)
6  
-    return shipping_calculator.constantize.new.send(:calculate_shipping, shipment)
  17
+    return calculator.calculate_shipping(shipment)
7 18
   end   
8 19
   
9 20
   def available?(order)
10  
-    calculator = shipping_calculator.constantize.new                               
11 21
     return true unless calculator.respond_to?(:available?)
12 22
     calculator.available?(order)    
13 23
   end
12  app/views/admin/shipping_methods/_form.html.erb
@@ -9,6 +9,14 @@
9 9
   </tr>
10 10
 	<tr>
11 11
     <td><%=t("shipping_calculator")%>:</td>
12  
-    <td><%= f.text_field :shipping_calculator, {"style" => "width:200px"} %></td>
  12
+    <td><%= f.collection_select(:calculator_type, @shipping_calculators, :to_s, :to_s, {}, {:id=> "calc-type", "style" => "width:200px"}) %></td>
13 13
   </tr>
14  
-</table>
  14
+</table>
  15
+
  16
+<h2><%= t('settings') %></h2>
  17
+<div class="calculator-settings">
  18
+  <% f.fields_for :calculator do |calculator_form| %>
  19
+    <%= preference_fields(@shipping_method.calculator, calculator_form) %>
  20
+  <% end %>
  21
+</div>
  22
+<div id="calculator-settings-warning"><%= t('calculator_settings_warning')%></div>
2  app/views/admin/shipping_methods/edit.html.erb
... ...
@@ -1,6 +1,6 @@
1 1
 <h1><%= t("editing_shipping_method") %></h1>
2 2
 <%= error_messages_for :shipping_rate %>
3  
-<% form_for(:shipping_method, :url => object_url, :html => { :method => :put }) do |f| %>
  3
+<% form_for(@shipping_method, :url => object_url, :html => { :method => :put }) do |f| %>
4 4
   <%= render :partial => "form", :locals => { :f => f } %>
5 5
   <p>
6 6
     <%=submit_tag t("update")%>
2  app/views/admin/shipping_methods/index.html.erb
@@ -21,7 +21,7 @@
21 21
     <tr id="<%= dom_id shipping_method %>">
22 22
       <td width="100px"><%= shipping_method.name %></td>
23 23
       <td width="100px"><%= shipping_method.zone.name %></td>
24  
-      <td width="100px"><%= shipping_method.shipping_calculator %></td>      
  24
+      <td width="100px"><%= shipping_method.calculator.to_s %></td>      
25 25
       <td>
26 26
       	<%= link_to_edit shipping_method %> &nbsp;
27 27
       	<%= link_to_delete shipping_method %>
7  app/views/layouts/admin.html.erb
@@ -8,15 +8,14 @@
8 8
   <%= stylesheet_link_tag 'admin/admin-reset', 'admin/grids', 'admin/admin-typography', 'admin/admin-forms', 'admin/admin-tables', 'admin/admin', :cache => 'admin-all' %>
9 9
 
10 10
   <%= javascript_include_tag :defaults %> <!-- TODO: Remove.  See Issue #320 -->
11  
-  <%= javascript_include_tag 'jquery-1.3.2.min', 'spree', 'nested-attribute', 'zone', :cache => 'jquery-and-extras' %>
12  
-  <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %> 
  11
+  <%= javascript_include_tag 'jquery-1.3.2.min', 'spree', 'nested-attribute', 'zone', 'calculator', :cache => 'jquery-and-extras' %>
  12
+  <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>   
  13
+  <%= javascript_include_tag 'jquery.alerts/jquery.alerts.js' %>                                           
13 14
   
14  
-  <%= javascript_include_tag 'jquery.alerts/jquery.alerts.js' %>
15 15
 	<%= stylesheet_link_tag '/javascripts/jquery.alerts/jquery.alerts.css' %>
16 16
 	<%= stylesheet_link_tag '/javascripts/jquery.alerts/jquery.alerts.spree.css' %>
17 17
 	
18 18
 	<%= javascript_tag "jQuery.alerts.dialogClass = 'spree';" %> 
19  
-	
20 19
   <%= yield :head %>
21 20
 </head>
22 21
 <body class='yui-skin-sam admin'>
7  config/locales/en-US.yml
@@ -270,7 +270,8 @@ en-US:
270 270
   extensions: Extensions
271 271
   filename: Filename
272 272
   final_confirmation: "Final Confirmation"
273  
-  first_name: "First Name"
  273
+  first_name: "First Name"                 
  274
+  flat_rate_amount: Amount
274 275
   forgot_password: "Forgot Password"
275 276
   gateway: Gateway
276 277
   gateway_configuration: "Gateway configuration"
@@ -452,7 +453,9 @@ en-US:
452 453
   send_copy_of_orders_mails_to: Send Copy of Order Mails To         
453 454
   send_mails_as: Send Mails As                    
454 455
   send_order_mails_as: Send Order Mails As   
455  
-  server_error: "The server returned an error"
  456
+  server_error: "The server returned an error"  
  457
+  settings: Settings
  458
+  calculator_settings_warning: "If you are changing the calculator type, you must save first before you can edit the calculator settings"
456 459
   ship: ship
457 460
   ship_address: "Ship Address"
458 461
   shipment: Shipment
3  config/routes.rb
@@ -87,7 +87,8 @@
87 87
     admin.resources :shipping_methods
88 88
     admin.resources :shipping_categories
89 89
     admin.resources :tax_rates
90  
-    admin.resource  :tax_settings      
  90
+    admin.resource  :tax_settings    
  91
+    admin.resources :calculators
91 92
   end                   
92 93
 
93 94
   
22  db/migrate/20090715172345_create_calculators.rb
... ...
@@ -0,0 +1,22 @@
  1
+class CreateCalculators < ActiveRecord::Migration
  2
+  def self.up
  3
+    create_table :calculators do |t|
  4
+      t.string :type
  5
+      t.references :calculable, :polymorphic => true, :null => false
  6
+      t.timestamps
  7
+    end          
  8
+    change_table :shipping_methods do |t|
  9
+      t.remove :shipping_calculator
  10
+    end                                        
  11
+    ShippingMethod.all.each do |shipping_method|  
  12
+      FlatRateShippingCalculator.create(:calculable => shipping_method)
  13
+    end    
  14
+  end
  15
+
  16
+  def self.down
  17
+    drop_table :calculators
  18
+    change_table :shipping_methods do |t|
  19
+      t.string :shipping_calculator
  20
+    end
  21
+  end
  22
+end
12  db/sample/calculators.yml
... ...
@@ -0,0 +1,12 @@
  1
+ups_ground:
  2
+  calculable: ups_ground
  3
+  calculable_type: ShippingMethod
  4
+  type: FlatRateShippingCalculator
  5
+ups_two_day:
  6
+  calculable: ups_two_day
  7
+  calculable_type: ShippingMethod
  8
+  type: FlatRateShippingCalculator
  9
+ups_one_day:
  10
+  calculable: ups_one_day
  11
+  calculable_type: ShippingMethod
  12
+  type: FlatRateShippingCalculator
15  db/sample/preferences.yml
... ...
@@ -0,0 +1,15 @@
  1
+flat_rate_ground:
  2
+  attribute: flat_rate_amount
  3
+  owner: ups_ground
  4
+  owner_type: Calculator
  5
+  value: 5
  6
+flat_rate_two_day:
  7
+  attribute: flat_rate_amount
  8
+  owner: ups_two_day
  9
+  owner_type: Calculator
  10
+  value: 10
  11
+flat_rate_one_day:
  12
+  attribute: flat_rate_amount
  13
+  owner: ups_one_day
  14
+  owner_type: Calculator
  15
+  value: 15      
13  db/sample/shipping_methods.yml
... ...
@@ -1,16 +1,9 @@
1 1
 ups_ground:
2 2
   name: UPS Ground
3  
-  zone: available_shipping
4  
-  shipping_calculator: Spree::FlatRateShipping::Calculator
  3
+  zone_id: 2
5 4
 ups_two_day:
6 5
   name: UPS Two Day
7  
-  zone: available_shipping
8  
-  shipping_calculator: Spree::FlatRateShipping::Calculator
  6
+  zone_id: 2
9 7
 ups_one_day:
10 8
   name: UPS One Day
11  
-  zone: available_shipping
12  
-  shipping_calculator: Spree::FlatRateShipping::Calculator
13  
-one_option:
14  
-  name: Only one option
15  
-  zone: one_ship_option
16  
-  shipping_calculator: Spree::FlatRateShipping::Calculator
  9
+  zone_id: 2
16  db/sample/zone_members.yml
... ...
@@ -1,16 +0,0 @@
1  
-usa_member:
2  
-  zone: available_shipping
3  
-  zoneable_id: 214
4  
-  zoneable_type: Country
5  
-canada_member:
6  
-  zone: available_shipping
7  
-  zoneable_id: 35
8  
-  zoneable_type: Country
9  
-uk_one_ship_opt:
10  
-  zone: one_ship_option
11  
-  zoneable_id: 213
12  
-  zoneable_type: Country
13  
-uae_one_ship_opt:
14  
-  zone: one_ship_option
15  
-  zoneable_id: 212                # UAE, just cos it's close to US/UK in the list
16  
-  zoneable_type: Country
6  db/sample/zones.yml
... ...
@@ -1,6 +0,0 @@
1  
-available_shipping:
2  
-  name: North America
3  
-  description: USA + Canada
4  
-one_ship_option:
5  
-  name: Zone with one shipping option 
6  
-  description: Zone with one shipping option 
4  generate
... ...
@@ -0,0 +1,4 @@
  1
+Script started on Wed Jul 15 13:22:29 2009
  2
+script: resource: No such file or directory
  3
+
  4
+Script done on Wed Jul 15 13:22:29 2009
13  public/javascripts/calculator.js
... ...
@@ -0,0 +1,13 @@
  1
+$j(function() {                                                                    
  2
+  var original_calc_type = $j('#calc-type').attr('value');
  3
+  $j('div#calculator-settings-warning').hide();
  4
+  $j('#calc-type').change(function() { 
  5
+    if ($j('#calc-type').attr('value') == original_calc_type) {
  6
+      $j('div.calculator-settings').show();
  7
+      $j('div#calculator-settings-warning').hide();
  8
+    } else {
  9
+      $j('div.calculator-settings').hide();
  10
+      $j('div#calculator-settings-warning').show();
  11
+    }
  12
+  });
  13
+})
4  public/stylesheets/admin/admin.css
@@ -424,6 +424,10 @@ span.current_page {
424 424
 	border: 1px solid navy;
425 425
 	background-color: #2e6ab1;
426 426
 	color: #FFF;
  427
+}                  
  428
+
  429
+div#calculator-settings-warning {
  430
+ color: #f00;
427 431
 }
428 432
 #progress{
429 433
 	display:none;
59  spec/models/shipping_method_spec.rb
... ...
@@ -1,59 +0,0 @@
1  
-require File.dirname(__FILE__) + '/../spec_helper'
2  
-
3  
-class MockCalculator           
4  
-  def available?(shipment)
5  
-    true
6  
-  end
7  
-  def calculate_shipping(shipment)
8  
-    2.5
9  
-  end
10  
-end
11  
-
12  
-class MockUnavailableCalculator           
13  
-  def available?(shipment)
14  
-    false
15  
-  end
16  
-end
17  
-
18  
-describe ShippingMethod do
19  
-  before(:each) do
20  
-    @calculator = MockCalculator.new
21  
-    MockCalculator.stub!(:new, :return => @calculator)
22  
-    @zone = mock_model(Zone)
23  
-    @address = mock_model(Address)
24  
-    @shipping_method = ShippingMethod.new(:zone => @zone, :shipping_calculator => "MockCalculator")
25  
-    @shipment = mock_model(Shipment, :address => @address)
26  
-  end
27  
-
28  
-  describe "available?" do      
29  
-    it "should return true if the calculator indicates method is supported" do
30  
-      @shipping_method.available?(@shipment).should be_true
31  
-    end
32  
-    it "should return false if the calculator indicates method is not supported"  do
33  
-      @shipping_method = ShippingMethod.new(:zone => @zone, :shipping_calculator => "MockUnavailableCalculator")
34  
-      @shipping_method.available?(@shipment).should be_false
35  
-    end
36  
-  end
37  
-  
38  
-  describe "calculate_shipping" do
39  
-    it "should be 0 if the shipping address does not fall within the method's zone" do
40  
-      @zone.stub!(:include?).with(@address).and_return(false)
41  
-      @shipping_method.calculate_shipping(@shipment).should == 0
42  
-    end
43  
-    describe "when the shipping address is included within the method's zone" do
44  
-      before :each do
45  
-        @zone.stub!(:include?).with(@address).and_return(true)
46  
-        # TODO - stub out instatiation code        
47  
-      end
48  
-      it "should use the calculate_shipping method of the specified calculator" do
49  
-        @calculator = MockCalculator.new
50  
-        MockCalculator.stub!(:new, :return => @calculator)
51  
-        @calculator.should_receive(:calculate_shipping).with(@shipment)
52  
-        @shipping_method.calculate_shipping(@shipment)
53  
-      end
54  
-      it "should return the correct amount" do
55  
-        @shipping_method.calculate_shipping(@shipment).should == 2.5
56  
-      end
57  
-    end
58  
-  end
59  
-end
12  test/factories.rb
@@ -21,7 +21,8 @@
21 21
 end
22 22
 
23 23
 Factory.define :shipment do |f|
24  
-  f.association :shipping_method
  24
+  f.association :shipping_method 
  25
+  f.association :order
25 26
 end
26 27
 
27 28
 Factory.define :shipping_method do |f|
@@ -131,4 +132,13 @@
131 132
 Factory.define :credit do |f|
132 133
   f.amount 2.00
133 134
   f.description "20% Off"
  135
+end                
  136
+
  137
+Factory.define :shipping_method do |f|
  138
+  f.association :zone    
  139
+  f.name { Factory.next(:name) }
  140
+end
  141
+
  142
+Factory.define :calculator, :class => :flat_rate_shipping_calculator do |f|
  143
+  f.association :calculable, :factory => :shipping_method
134 144
 end
7  test/fixtures/calculators.yml
... ...
@@ -0,0 +1,7 @@
  1
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2
+
  3
+# one:
  4
+#   column: value
  5
+#
  6
+# two:
  7
+#   column: value
8  test/functional/calculators_controller_test.rb
... ...
@@ -0,0 +1,8 @@
  1
+require 'test_helper'
  2
+
  3
+class CalculatorsControllerTest < ActionController::TestCase
  4
+  # Replace this with your real tests.
  5
+  test "the truth" do
  6
+    assert true
  7
+  end
  8
+end
8  test/test_helper.rb
@@ -18,7 +18,13 @@ class ActiveSupport::TestCase
18 18
       super action, @params.merge( params || {} ), *extras if @params
19 19
     end
20 20
   end
21  
-end 
  21
+end  
  22
+
  23
+class TestShippingCalc < ShippingCalculator  
  24
+  def calculate_shipping(order)
  25
+    5
  26
+  end
  27
+end
22 28
 
23 29
 def setup
24 30
   super
6  test/unit/calculator_test.rb
... ...
@@ -0,0 +1,6 @@
  1
+require 'test_helper'
  2
+
  3
+class CalculatorTest < ActiveSupport::TestCase
  4
+  should_belong_to :calculable
  5
+  should_validate_presence_of :calculable_id
  6
+end
4  test/unit/helpers/calculators_helper_test.rb
... ...
@@ -0,0 +1,4 @@
  1
+require 'test_helper'
  2
+
  3
+class CalculatorsHelperTest < ActionView::TestCase
  4
+end
37  test/unit/shppping_method_test.rb
... ...
@@ -0,0 +1,37 @@
  1
+require 'test_helper'
  2
+
  3
+class ShippingMethodTest < ActiveSupport::TestCase
  4
+  context "instance" do
  5
+    setup do 
  6
+      @calculator = TestShippingCalc.create #Factory(:calculator)
  7
+      @shipping_method = Factory(:shipping_method, :calculator => @calculator)  
  8
+      @zone = @shipping_method.zone                 
  9
+      @shipment = Factory(:shipment)
  10
+      @order = @shipment.order           
  11
+    end
  12
+    context "when calculator indicates method is supported" do
  13
+      setup { @calculator.stub!(:available?, :return => true) }
  14
+      should "be available" do
  15
+        assert @shipping_method.available?(@order)
  16
+      end
  17
+      context "when the shipping address does not fall within the method's zone" do
  18
+        setup { @zone.stub!(:include?, :return => false) } 
  19
+        should "return 0 when calculating shipping for that method" do
  20
+          assert_equal 0, @shipping_method.calculate_shipping(@shipment)
  21
+        end      
  22
+      end
  23
+      context "when the shipping address falls within the method's zone" do
  24
+        setup { @zone.stub!(:include?, :return => true) }
  25
+        should "return the amount as calculated by the method's calculator" do
  26
+          assert_equal 5, @shipping_method.calculate_shipping(@shipment)
  27
+        end      
  28
+      end
  29
+    end
  30
+    context "when calculator indicates method is not supported" do
  31
+      setup { @calculator.stub!(:available?, :return => false) }
  32
+      should "not be available" do
  33
+        assert !@shipping_method.available?(@order)
  34
+      end
  35
+    end
  36
+  end                 
  37
+end
7  vendor/extensions/flat_rate_shipping/app/models/flat_rate_shipping_calculator.rb
... ...
@@ -0,0 +1,7 @@
  1
+class FlatRateShippingCalculator < ShippingCalculator
  2
+  preference :flat_rate_amount, :decimal, :default => 0  
  3
+  
  4
+  def calculate_shipping(shipment)
  5
+    return self.preferred_flat_rate_amount
  6
+  end  
  7
+end
1  vendor/extensions/flat_rate_shipping/flat_rate_shipping_extension.rb
@@ -6,6 +6,5 @@ class FlatRateShippingExtension < Spree::Extension
6 6
   description "Provides FlatRate shiping_calculator" 
7 7
 
8 8
   def activate
9  
-    # admin.tabs.add "Flat Rate Shipping", "/admin/flat_rate_shipping", :after => "Layouts", :visibility => [:all]
10 9
   end
11 10
 end
7  vendor/extensions/flat_rate_shipping/lib/flat_rate_shipping_configuration.rb
... ...
@@ -1,7 +0,0 @@
1  
-class FlatRateShippingConfiguration < Configuration
2  
-
3  
-  preference :flat_rate_amount, :decimal, :default => 12.99
4  
-  
5  
-  validates_presence_of :name
6  
-  validates_uniqueness_of :name
7  
-end
22  vendor/extensions/flat_rate_shipping/lib/spree/flat_rate_shipping/config.rb
... ...
@@ -1,22 +0,0 @@
1  
-module Spree
2  
-  module FlatRateShipping
3  
-    # Singleton class to access the tax configuration object (TaxConfiguration.first by default) and it's preferences.
4  
-    #
5  
-    # Usage:
6  
-    #   Spree::FlatRateShipping::Config[:foo]                  # Returns the foo preference
7  
-    #   Spree::FlatRateShipping::Config[]                      # Returns a Hash with all the tax preferences
8  
-    #   Spree::FlatRateShipping::Config.instance               # Returns the configuration object (TaxConfiguration.first)
9  
-    #   Spree::FlatRateShipping::Config.set(preferences_hash)  # Set the tax preferences as especified in +preference_hash+
10  
-    class Config
11  
-      include Singleton
12  
-      include PreferenceAccess
13  
-    
14  
-      class << self
15  
-        def instance
16  
-          return nil unless ActiveRecord::Base.connection.tables.include?('configurations')
17  
-          FlatRateShippingConfiguration.find_or_create_by_name("Default tax configuration")
18  
-        end
19  
-      end
20  
-    end
21  
-  end
22  
-end

0 notes on commit dfcb544

Please sign in to comment.
Something went wrong with that request. Please try again.