spree_exactor 1.1.1.112920126

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile.lock +231 -0
  3. data/README.md +21 -0
  4. data/app/assets/javascripts/admin/exactor_settings.js +2 -0
  5. data/app/assets/javascripts/admin/spree_exactor.js +1 -0
  6. data/app/assets/javascripts/store/spree_exactor.js +1 -0
  7. data/app/assets/stylesheets/admin/spree_exactor.css +3 -0
  8. data/app/assets/stylesheets/exactor_settings.css +4 -0
  9. data/app/assets/stylesheets/store/spree_exactor.css +3 -0
  10. data/app/controllers/spree/admin/exactor_settings_controller.rb +34 -0
  11. data/app/helpers/exactor_api_objects.rb +387 -0
  12. data/app/helpers/exactor_api_service.rb +96 -0
  13. data/app/helpers/spree_exactor_connector.rb +380 -0
  14. data/app/models/spree/adjustment_decorator.rb +41 -0
  15. data/app/models/spree/calculator/exactor_tax_calculator.rb +87 -0
  16. data/app/models/spree/exactor_setting.rb +140 -0
  17. data/app/models/spree/line_item_decorator.rb +31 -0
  18. data/app/models/spree/order_decorator.rb +126 -0
  19. data/app/models/spree/payment_decorator.rb +15 -0
  20. data/app/models/spree/tax_category_decorator.rb +31 -0
  21. data/app/models/spree/tax_rate_decorator.rb +46 -0
  22. data/app/models/spree/user_decorator.rb +7 -0
  23. data/app/models/spree/zone_decorator.rb +31 -0
  24. data/app/overrides/spree_exactor_overrides.rb +27 -0
  25. data/app/views/spree/admin/exactor_settings/show.html.erb +113 -0
  26. data/config/locales/en.yml +10 -0
  27. data/config/routes.rb +6 -0
  28. data/db/migrate/20120624223025_create_exactor_settings.rb +20 -0
  29. data/db/migrate/20120627130223_add_exactor_info_to_order.rb +8 -0
  30. data/db/migrate/20120705103207_add_exactor_indicator_to_tax_rates.rb +5 -0
  31. data/db/migrate/20120713152512_modify_dependent_entities.rb +6 -0
  32. data/db/migrate/20120813124740_extend_user.rb +5 -0
  33. data/db/migrate/20120815104739_add_exactor_tor_inline_tax.rb +5 -0
  34. data/lib/generators/spree_exactor/install/install_generator.rb +80 -0
  35. data/lib/generators/spree_exactor/uninstall/uninstall_generator.rb +24 -0
  36. data/lib/spree_exactor/engine.rb +25 -0
  37. data/lib/spree_exactor.rb +2 -0
  38. data/spree_exactor.gemspec +66 -0
  39. metadata +197 -0
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ TaxCategory.class_eval do
3
+ attr_accessible :is_exactor_default
4
+ before_update :validate_for_exactor_default
5
+
6
+ private
7
+ def self.create_tax_category_entity
8
+ taxCategory = TaxCategory.new(:name => "Exactor Tax Category", :description => "Default Exactor Category",
9
+ :is_default => false, :is_exactor_default => true)
10
+ taxCategory.save()
11
+ return taxCategory
12
+ end
13
+
14
+ def self.find_or_create_exactor_tax_category()
15
+ taxCat = TaxCategory.where(:is_exactor_default => true)
16
+ if taxCat.empty?
17
+ taxCat = create_tax_category_entity()
18
+ else
19
+ taxCat = taxCat.first
20
+ end
21
+ return taxCat
22
+ end
23
+
24
+ def validate_for_exactor_default
25
+ if is_exactor_default? and changed_attributes.keys().include?('deleted_at')
26
+ raise Exception, "Cannot delete default Exactor Tax Category until Exactor plug-in is uninstalled"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,46 @@
1
+ module Spree
2
+ TaxRate.class_eval do
3
+ attr_accessible :is_exactor_default
4
+ before_destroy :validate_for_exactor_default
5
+ before_save :validate_on_update
6
+
7
+ def self.match(order)
8
+
9
+ return [] if order.shipping_method.nil? and order.shipments.empty?
10
+ all.select { |rate| rate.is_exactor_default?}
11
+ end
12
+
13
+ private
14
+ def self.create_tax_rate_entity
15
+ taxCat = TaxCategory.find_or_create_exactor_tax_category()
16
+ taxZone = Zone.find_or_create_exactor_zone()
17
+ taxRate = TaxRate.new(:amount=>0, :tax_category_id=>taxCat.id, :zone_id=>taxZone.id, :included_in_price => false)
18
+ TaxRate.update_all({:is_exactor_default=>false})
19
+ taxRate.is_exactor_default= true
20
+ taxRate.calculator_type= "Spree::Calculator::ExactorTaxCalculator"
21
+ taxRate.save()
22
+ return taxRate
23
+ end
24
+
25
+ def self.find_or_create_exactor_tax_rate
26
+ exactorTaxRate = TaxRate.where(:is_exactor_default=>true)
27
+ if exactorTaxRate.empty?
28
+ exactorTaxRate = create_tax_rate_entity()
29
+ end
30
+ end
31
+
32
+ def validate_for_exactor_default
33
+ if is_exactor_default?
34
+ raise Exception, "Cannot update default Exactor Tax Rate until Exactor plug-in is uninstalled"
35
+ end
36
+ end
37
+
38
+ def validate_on_update
39
+ if is_exactor_default? and !changed_attributes.keys().include?('is_exactor_default')
40
+ errors[:base] << "Cannot delete default Exactor Tax Rate until Exactor plug-in is uninstalled"
41
+ false
42
+ end
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,7 @@
1
+ module Spree
2
+ User.class_eval do
3
+ attr_accessible :exactor_exemption_id
4
+
5
+ validates_size_of :exactor_exemption_id, :within=>0..12
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ Zone.class_eval do
3
+ attr_accessible :is_exactor_default
4
+ before_destroy :validate_for_exactor_default
5
+
6
+ private
7
+ def self.create_zone_entity
8
+ zone = Zone.new(:name => "Exactor Tax Zone", :description=> "Default Exactor Zone",
9
+ :is_exactor_default=>true)
10
+ zone.save()
11
+ return zone
12
+ end
13
+
14
+ def self.find_or_create_exactor_zone()
15
+ taxZone = Zone.where(:is_exactor_default=>true)
16
+ if taxZone.empty?
17
+ taxZone = create_zone_entity()
18
+ else
19
+ taxZone = taxZone.first
20
+ end
21
+ return taxZone
22
+ end
23
+
24
+ def validate_for_exactor_default
25
+ if is_exactor_default?
26
+ raise Exception, "Cannot delete default Exactor Tax Zone until Exactor plug-in is uninstalled"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ Deface::Override.new(:virtual_path => "spree/admin/configurations/index",
2
+ :name => "exactor_settings_admin",
3
+ :insert_bottom => "[data-hook='admin_configurations_menu']",
4
+ :text => "<tr>
5
+ <td><%= link_to t(:exactor_settings), admin_exactor_settings_path %></td>
6
+ <td><%= t('Exactor settings page') %></td>
7
+ </tr>",
8
+ :disabled => false)
9
+ Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
10
+ :name => "exactor_settings_admin_sidebar",
11
+ :insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
12
+ :text => "<%= configurations_sidebar_menu_item t(:exactor_settings), admin_exactor_settings_path %>",
13
+ :disabled => false)
14
+ Deface::Override.new(:virtual_path => "spree/admin/orders/_form",
15
+ :name => "exactor_is_edit",
16
+ :insert_bottom => "[data-hook='admin_order_form_line_items_headers']",
17
+ :text => '<input type="hidden" id="order_exactor_is_edit" name="order[exactor_is_edit]" value="true" /> ',
18
+ :disabled => false)
19
+ Deface::Override.new(:virtual_path => "spree/admin/users/_form",
20
+ :name => "exactor_exemption_id",
21
+ :insert_bottom => "[data-hook='admin_user_form_fields']",
22
+ :text => '<%= f.field_container :exactor_exemption_id do %>
23
+ <%= f.label :exactor_exemption_id, "Exactor Exemption ID" %><br />
24
+ <%= f.text_field :exactor_exemption_id %>
25
+ <%= f.error_message_on :exactor_exemption_id %>
26
+ <% end %>',
27
+ :disabled => false)
@@ -0,0 +1,113 @@
1
+ <%= render :partial => 'spree/admin/shared/configuration_menu' %>
2
+ <div><h1 style="float:left">Exactor settings</h1>
3
+ <span style="float:right;display: inline;
4
+ color: #666;
5
+ margin-top: 10px;
6
+ font-size: 8pt;">Exactor Plug-in Version: <%= SpreeExactorConnector::SpreeExactorConnector::PLUGIN_VERSION %></span></div>
7
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @setting } %>
8
+ <% action = @setting.id.nil? ? "create":"update" %>
9
+ <%= form_for @setting, :url => { :action => action , :id =>@setting.id } do |f| %>
10
+ <table class="index">
11
+ <thead>
12
+ <tr>
13
+ <th colspan="8">
14
+ <span>Exactor Account Settings</span>
15
+ <%if @setting.id.nil? %>
16
+ <span style="margin-left: 15px;font-weight: normal;">
17
+ <a href="https://merchant.exactor.com/account/signup/application" target="_blank">Click Here</a>
18
+ to sign up for an Exactor Account
19
+ </span>
20
+ <%end%>
21
+ </th>
22
+ </tr>
23
+ </thead>
24
+ <tbody>
25
+ <tr>
26
+ <td class="lbl-col"><%=f.label :user_id, "User ID" %></td>
27
+ <td class="val-col" colspan="3"> <%= f.text_field :user_id %></td>
28
+ <td class="lbl-col"> <%=f.label :merchant_id, "Account #" %></td>
29
+ <td class="val-col" colspan="3"> <%= f.text_field :merchant_id %></td>
30
+ </tr>
31
+ </tbody>
32
+ </table>
33
+
34
+ <table class="index">
35
+ <thead>
36
+ <tr>
37
+ <th colspan="8">Processing Options</th>
38
+ </tr>
39
+ </thead>
40
+ <tbody>
41
+ <tr>
42
+ <td class="lbl-col"><%=f.label :ship_effective_date, "Effective Date" %></td>
43
+ <td class="val-col" colspan="3"> <%= f.date_select :effective_date %></td>
44
+ <td class="lbl-col"><%=f.label :shipping_include_handling, "Do shipping charges include handling?" %></td>
45
+ <td class="val-col" colspan="3"> <%= f.check_box :shipping_include_handling %></td>
46
+ </tr>
47
+ <tr>
48
+ <td class="lbl-col"><%=f.label :commit_option, "Commit Options" %></td>
49
+ <td class="val-col" colspan="3"> <%= f.collection_select :commit_option, f.object.all_commit_options, :id, :name, {} %></td>
50
+ <td class="lbl-col"> <%=f.label :sku_source, "SKU Source" %></td>
51
+ <td class="val-col" colspan="3"> <%= f.collection_select :sku_source, f.object.all_sku_sources, :id, :name, {} %></td>
52
+ </tr>
53
+ </tbody>
54
+ </table>
55
+
56
+
57
+ <table class="index">
58
+ <thead>
59
+ <tr>
60
+ <th colspan="8">Ship From Information</th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <tr > <!-- Full name-->
65
+ <td class="lbl-col"><%=f.label :ship_from_name, "Full Name" %></td>
66
+ <td class="val-col" colspan="3"><%= f.text_field :ship_from_name %></td>
67
+ </tr>
68
+ <tr > <!-- Street1, Street2-->
69
+ <td class="lbl-col"><%=f.label :ship_from_street1, "Street 1" %> </td>
70
+ <td class="val-col" colspan="3"><%= f.text_field :ship_from_street1 %></td>
71
+ <td class="lbl-col"><%=f.label :ship_from_street2, "Street 2" %></td>
72
+ <td class="val-col" colspan="3"><%= f.text_field :ship_from_street2 %></td>
73
+ </tr>
74
+ <tr> <!-- City, ZIP-->
75
+ <td class="lbl-col"> <%=f.label :ship_from_city, "City" %></td>
76
+ <td class="val-col" colspan="3"><%= f.text_field :ship_from_city %></td>
77
+ <td class="lbl-col"><%=f.label :ship_from_zip, "Postal Code" %></td>
78
+ <td class="val-col" colspan="3"><%= f.text_field :ship_from_zip %></td>
79
+ </tr>
80
+ <tr> <!-- Country, State-->
81
+ <td class="lbl-col">
82
+ <%=f.label :state_id, "State" %>
83
+ </td>
84
+ <td class="val-col" colspan="3">
85
+ <span id="sstate">
86
+ <%= f.text_field :state_name, :style => "width:150px; display: #{f.object.country.states.empty? ? 'block' : 'none' };", :disabled => !f.object.country.states.empty? %>
87
+ <%= f.collection_select :state_id, f.object.country.states.sort, :id, :name, {:include_blank => true}, {:style => "width:150px; display: #{f.object.country.states.empty? ? 'none' : 'block' };", :disabled => f.object.country.states.empty?} %>
88
+ </span>
89
+ </td>
90
+ <td class="lbl-col">
91
+ <%=f.label :country_id, "Country" %>
92
+ </td>
93
+ <td class="val-col" colspan="3">
94
+ <span id="scountry">
95
+ <%= f.collection_select :country_id, Spree::Country.all, :id, :name, {}, {:style => 'width: 150px;'} %>
96
+ </span>
97
+ </td>
98
+ </tr>
99
+ </tbody>
100
+ </table>
101
+
102
+ <%= f.submit "Save Exactor Settings" %>
103
+ <% end %>
104
+
105
+
106
+ <% content_for :head do %>
107
+ <%= javascript_include_tag '/states' %>
108
+ <script type="text/javascript">
109
+ $(document).ready(function(){
110
+ $('span#scountry select').change(function() { update_state('s'); });
111
+ });
112
+ </script>
113
+ <% end %>
@@ -0,0 +1,10 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
6
+ exactor_settings_updated: "Exactor settings have been successfully updated"
7
+ exactor_settings_created: "Exactor settings have been successfully created"
8
+
9
+
10
+
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ resource :exactor_settings ,:only => [:show, :update, :create]
4
+ end
5
+ # Add your extension routes here
6
+ end
@@ -0,0 +1,20 @@
1
+ class CreateExactorSettings < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_exactor_settings do |t|
4
+ t.string :merchant_id
5
+ t.string :user_id
6
+ t.string :ship_from_name
7
+ t.string :ship_from_street1
8
+ t.string :ship_from_street2
9
+ t.string :ship_from_city
10
+ t.integer :state_id
11
+ t.string :state_name
12
+ t.string :ship_from_zip
13
+ t.integer :country_id
14
+ t.date :effective_date
15
+ t.string :sku_source
16
+ t.string :commit_option
17
+ t.boolean :shipping_include_handling
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ class AddExactorInfoToOrder < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_orders, :exactor_invoice_transaction, :string
4
+ add_column :spree_orders, :exactor_commit_transaction, :string
5
+ add_column :spree_orders, :exactor_order_hash_sum, :string
6
+ add_column :spree_orders, :exactor_is_edit, :string
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddExactorIndicatorToTaxRates < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_tax_rates, :is_exactor_default, :boolean
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class ModifyDependentEntities < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_tax_categories, :is_exactor_default, :boolean
4
+ add_column :spree_zones, :is_exactor_default, :boolean
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class ExtendUser < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_users, :exactor_exemption_id, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddExactorTorInlineTax < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_line_items, :exactor_inline_tax, :decimal, :default=>0.00
4
+ end
5
+ end
@@ -0,0 +1,80 @@
1
+ require 'rails/generators'
2
+
3
+ module SpreeExactor
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+
7
+ argument :_plugin_version, :type => :string, :required => true, :desc => "Exactor Spree Plug-in version"
8
+ argument :_environment, :type => :string, :required => false, :desc => "Spree environment type (development, production)", :default=>""
9
+
10
+ def install
11
+ supported_versions '1.1.1.112920126'=>['1.1.1','1.1.2','1.1.3']
12
+ unless @supported_versions.include? _plugin_version
13
+ puts "Unknown plug-in version. Try any of those: "+ @supported_versions.keys.to_s
14
+ exit(0)
15
+ end
16
+ spree_versions = @supported_versions.values_at(_plugin_version)[0]
17
+ answer=ask("ATTENTION! This plug-in supports only these versions of Spree: "+spree_versions.to_s+" Is your version of Spree listed there? [Y/n] \n")
18
+ if (answer.downcase=='n')
19
+ puts "Sorry, this installer cannot be used for other versions of Spree."
20
+ exit(0)
21
+ end
22
+ puts "Removing all previous Exactor dependencies (if exist)... "
23
+ gsub_file "Gemfile", /^\s*gem\s* "spree_exactor"\s*,\s*.{5,17}$/, ""
24
+ puts " * Done"
25
+ puts "Adding Exactor plugin of version "+_plugin_version+" to your gem file..."
26
+ append_file "Gemfile", "\n", :force => true
27
+ gem 'spree_exactor', _plugin_version
28
+ puts " * Done"
29
+ puts "Executing bundle update..."
30
+ run 'bundle update'
31
+ puts " * Done"
32
+
33
+ puts "Performing resource migrations..."
34
+ add_javascripts
35
+ add_stylesheets
36
+ puts " * Done"
37
+
38
+ puts "Performing database migrations..."
39
+ add_migrations
40
+ run_migrations _environment
41
+ puts " * Done"
42
+ end
43
+
44
+ def supported_versions(versions={})
45
+ @supported_versions=versions
46
+ end
47
+
48
+
49
+ protected
50
+
51
+ def add_javascripts
52
+ # append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_exactor\n"
53
+ # append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_exactor\n"
54
+ end
55
+
56
+ def add_stylesheets
57
+ # inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_exactor\n", :before => /\*\//, :verbose => true
58
+ # inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_exactor\n", :before => /\*\//, :verbose => true
59
+ end
60
+
61
+ def add_migrations
62
+ run "bundle exec rake railties:install:migrations FROM=spree_exactor"
63
+ end
64
+
65
+ def run_migrations(env='')
66
+ if (env.strip.empty?)
67
+ puts 'Running migrations with environment set in config/environment'
68
+ run "bundle exec rake --require='./config/environment' db:migrate"
69
+ else
70
+ puts "Running migrations with forced environment '#{env.strip}' "
71
+ run "bundle exec rake db:migrate RAILS_ENV='#{env.strip}'"
72
+ end
73
+
74
+ end
75
+
76
+
77
+ end
78
+ end
79
+ end
80
+
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+
3
+ module SpreeExactor
4
+ module Generators
5
+ class UninstallGenerator < Rails::Generators::Base
6
+
7
+ argument :_plugin_version, :type => :string, :required => true, :desc => "Exactor Spree Plug-in version"
8
+
9
+ def uninstall
10
+ puts "Removing all previous Exactor dependencies (if exist)... "
11
+ gsub_file "Gemfile", /^\s*gem\s* "spree_exactor"\s*,\s*.{5,17}$/, ""
12
+ puts " * Done"
13
+ puts "Executing bundle update..."
14
+ run 'bundle update'
15
+ puts " * Done"
16
+ puts "Removing spree_exactor-"+_plugin_version
17
+ run 'gem uninstall spree_exactor -v '+_plugin_version
18
+ puts " * Done"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+